Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force redeployment of my API Gateway using Cloudformation

I'm using AWS CloudFormation to create an API gateway. I have a AWS::ApiGateway::Deployment resource, which works great when I create my stack. However, if I update my stack (with a change in the AWS::ApiGateway::Method, for example), the API does not get deployed again. I have to manually deploy the API in API Gateway.

Anyone know how I can automatically deploy the gateway when the stack is updated?

like image 473
Manu Avatar asked Jul 14 '16 01:07

Manu


People also ask

How do I redeploy API gateway?

Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway . In the APIs navigation pane, choose the API you want to deploy. In the Resources navigation pane, choose Actions. From the Actions drop-down menu, choose Deploy API.

How do you deploy using CloudFormation?

AWS CloudFormation requires you to use a change set to create a template that includes transforms. Instead of independently creating and then initiating a change set, use the aws cloudformation deploy command. When you run this command, it creates a change set, initiates the change set, and then terminates.


Video Answer


1 Answers

I may be late, but here are the options which which you do a redeployment if a API resources changes, may be helpful to people who still looking for options -

  1. Try AutoDeploy to true. If you are using V2 version of deployment. Note that you need to have APIGW created through V2. V1 and V2 are not compatible to each other. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-autodeploy

  2. Lambda backed custom resource, Lambda inturn call createDeployment API - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html

  3. CodePipeline that has an action that calls a Lambda Function much like the Custom Resource would - https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html

  4. SAM(Serverless Application Model) follows a similar syntax to CloudFormation which simplifies the resource creation into abstractions and uses those to build and deploy a normal CloudFormation template. https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html

  5. If you are using any abstraction layer to cloudformation like Sceptre, you can have a hook to call createDeployment after any-update to the resource https://sceptre.cloudreach.com/2.3.0/docs/hooks.html

I gone with third option since I kept using Sceptre for Cloudformation deployment. Implementing hooks in sceptre is easy as well.

like image 173
Athi Avatar answered Oct 23 '22 18:10

Athi