Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AWS API Gateway dynamic StageName for CICD

I’m trying to deploy an AWS API Gateway using Gitlab CICD pipelines. Since I have different environments, I want the StageName property of the API to be set dynamically i.e., StageName should be "dev" when deployed to dev stack, "prod" when deployed to prod stack. Below is the YAML script I used.

Mappings:
  StackEnv:
    dev-stack:
      envm: "dev"
    qa-stack:
      envm: "qa"
Resources:  
  TestingAPI:
    Type: AWS::Serverless::Api
    Properties:
      StageName: [!FindInMap [StackEnv, !Ref AWS::StackName, envm]]

It looks fine from above but when I try to deploy the API, I’m getting the error mentioned below.

[InvalidResourceException('TestingAPI', "Type of property 'StageName' is invalid.")] 

I can’t seem to understand why it should fail. If this approach won’t work, how can I pass the respective environment values to the StageName property without breaking the pipeline?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are wrapping the results of the !FindInMap function in [] making it a list. Remove the brackets:

      StageName: !FindInMap [StackEnv, !Ref AWS::StackName, envm]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading