Easy methods to Pressure Redeployment of AWS API Gateway utilizing AWS CloudFormation

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

template.yaml extract:

APIGatewayStage:
    Sort: 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__:
    Sort: AWS::ApiGateway::Deployment
    Properties:
      RestApiId: !Ref APIGateway
      Description: !Sub ${EnvironmentTagName} Deployment __TIMESTAMP__

  APIGateway:
    Sort: AWS::ApiGateway::RestApi
    Properties:
      Title: !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 ensure that 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