CloudFormation doesn't deploy to API gateway stages on update

后端 未结 8 1244
南笙
南笙 2020-12-25 11:47

When I run CloudFormation deploy using a template with API Gateway resources, the first time I run it, it creates and deploys to stages. The subsequent times I

相关标签:
8条回答
  • 2020-12-25 12:25

    From the blogspot post linked by TheClassic (best answer so far!), you have to keep in mind that if you aren't generating your templates with something that can insert a valid timestamp in place of $TIMESTAMP$, you must update that manually with a time stamp or otherwise unique ID. Here is my functional example, it successfully deletes the existing deployment and creates a new one, but I will have to update those unique values manually when I want to create another change set:

        rDeployment05012019355:
            Type: AWS::ApiGateway::Deployment
            DependsOn: rApiGetMethod
            Properties:
                RestApiId:
                    Fn::ImportValue: 
                        !Sub '${pApiCoreStackName}-RestApi'
                StageName: !Ref pStageName
    
        rCustomDomainPath:
            Type: AWS::ApiGateway::BasePathMapping
            DependsOn: [rDeployment05012019355]
            Properties:
                BasePath: !Ref pPathPart
                Stage: !Ref pStageName
                DomainName:
                    Fn::ImportValue: 
                        !Sub '${pApiCoreStackName}-CustomDomainName'
                RestApiId:
                    Fn::ImportValue: 
                        !Sub '${pApiCoreStackName}-RestApi'
    
    0 讨论(0)
  • 2020-12-25 12:26

    CloudFormation in Amazon's words is:

    AWS CloudFormation takes care of provisioning and configuring those resources for you http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html

    Redeployment of APIs is not a provisioning task... It is a promotion activity which is part of a stage in your software release process.

    AWS CodePipeline is a continuous delivery service you can use to model, visualize, and automate the steps required to release your software. http://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html

    CodePipeline also supports execution of Lambda functions from Actions in the pipeline. So, as advised before, create a Lambda function to deploy your API but call it from Codepipeline instead of CloudFormation.

    Consult this page for details: http://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html

    0 讨论(0)
提交回复
热议问题