CloudFormation does not deploy during API gateway phases when upgrading

When I launch CloudFormation deploy using a template with Gateway API resources, the first time it launches, it creates and deploys in stages. In subsequent periods of time, I run it, it updates resources, but does not deploy them in stages.

Is this behavior as intended? If so, how can I expand it into steps whenever it is updated?

(Terraform mentions a similar problem: https://github.com/hashicorp/terraform/issues/6613 )

+26
source share
5 answers

There seems to be no way to easily create a new deployment whenever one of your Cloudformation resources changes.

One way around this is to use a Lambda-enabled custom resource (see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html ).

Lambda should create a new deployment only if one of your resources is updated. To determine if one of your resources has been updated,
you will probably have to implement custom logic around this API call: http://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_DescribeStackEvents.html

To initiate updates to your user resource, I suggest you provide a cloud information setting that will be used to force updates to your user resource (for example, current time or version number).

Please note that you will have to add the DependsOn clause to your custom resource, which will include all resources related to your API. Otherwise, the deployment may be created before updating all API resources.

Hope this helps.

+12
source

CloudFormation in Amazon's words is:

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

Redistributing the APIs is not the task of providing ... This is a promotion action that is part of the software release phase.

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

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

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

+6
source

If a deployment is specified in your template, CloudFormation will create that deployment only if it does not already exist. When you try to run it again, it discovers that the deployment still exists, so it will not recreate it, and therefore, there will be no deployment. You need a new deployment identifier for the resource so that it creates a new deployment. Read this for more information: https://currentlyunnamed-theclassic.blogspot.com/2018/12/mastering-cloudformation-for-api.html

+4
source

From a blog post related to TheClassic (the best answer so far!), You should remember that if you are not generating your templates with something that can insert a valid timestamp instead of $ TIMESTAMP $, you must manually update it with timestamp or other unique identifier. Here is my functional example: it successfully deletes an existing deployment and creates a new one, but I will have to update these unique values โ€‹โ€‹manually when I want to create another set of changes:

  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' 
+3
source

Use SAM

AWS :: Serverless :: Api

It does the deployment for you when it does the conversion

-2
source

Source: https://habr.com/ru/post/1013697/


All Articles