Saturday, May 13, 2023
HomeSoftware EngineeringThe best way to Power Redeployment of AWS API Gateway utilizing AWS...

The best way to Power Redeployment of AWS API Gateway utilizing AWS CloudFormation


If in case you have an AWS API Gateway useful resource, and wish it to pressure a redeployment utilizing CloudFormation, then you need to use the TIMESTAMP trick.

template.yaml extract:

APIGatewayStage:
    Kind: AWS::ApiGateway::Stage
    Properties:
      StageName: !Sub ${EnvironmentTagName}
      RestApiId: !Ref APIGateway
      DeploymentId: !Ref APIGatewayDeployment__TIMESTAMP__
      TracingEnabled: true
      MethodSettings:
          - DataTraceEnabled: true
            HttpMethod: "*"
            LoggingLevel: INFO
            ResourcePath: "/*"
            MetricsEnabled: true

  APIGatewayDeployment__TIMESTAMP__:
    Kind: AWS::ApiGateway::Deployment
    Properties:
      RestApiId: !Ref APIGateway
      Description: !Sub ${EnvironmentTagName} Deployment __TIMESTAMP__

  APIGateway:
    Kind: AWS::ApiGateway::RestApi
    Properties:
      Identify: !Ref "AWS::StackName"
      ...

As we are able to see, on line 15 above, we use the __TIMESTAMP__ string within the APIGatewayDeployment stage.

Now we merely be sure to replace the template.yaml file with our CI run, changing the occurence of __TIMESTAMP__ with the TIMESTAMP variable generated:

TIMESTAMP="$(date +%s)"
sed -i "s/__TIMESTAMP__/${TIMESTAMP}/g" template.yaml
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments