implementing AWS CloudFormation Updating API Gateway Stages After Deploying Lambda Function
I'm getting frustrated with I'm getting frustrated with I'm working on a personal project and Quick question that's been bugging me - I'm working with an scenario where my AWS CloudFormation stack is not correctly updating the API Gateway stage after I deploy a new version of my Lambda function... I have defined my Lambda function and the associated API Gateway in a single CloudFormation template, but when I update the Lambda function code, the deployment does not seem to reflect the latest changes. Specifically, I'm using AWS CLI version 2.2.0 and CloudFormation template format version '2010-09-09'. Hereโs the relevant section of my CloudFormation template: ```yaml Resources: MyLambdaFunction: Type: AWS::Lambda::Function Properties: Handler: index.handler Role: arn:aws:iam::123456789012:role/service-role/MyLambdaRole Code: S3Bucket: my-bucket S3Key: my-function.zip Runtime: nodejs14.x MyApi: Type: AWS::ApiGateway::RestApi Properties: Name: MyAPI MyApiDeployment: Type: AWS::ApiGateway::Deployment Properties: RestApiId: !Ref MyApi StageName: prod Description: Deployment for production stage ApiGatewayStage: Type: AWS::ApiGateway::Stage Properties: RestApiId: !Ref MyApi StageName: prod MethodSettings: - HttpMethod: '*' ResourceId: !GetAtt MyApi.RootResourceId ThrottlingBurstLimit: 200 ThrottlingRateLimit: 100 ``` After deploying, when I run `aws cloudformation update-stack` with a new S3 key for the Lambda code, the API Gateway does not update the stage and continues to use the old Lambda function version. Iโve tried adding a `DependsOn` attribute in the `ApiGatewayStage` resource, but it still doesn't work. Additionally, Iโve checked the CloudFormation events and they show no errors during the update, but the API Gateway stage still points to the previous version of my Lambda. Iโve also tried explicitly referencing the `MyLambdaFunction` in the `ApiGatewayStage` properties, but Iโm unsure how to make the API Gateway aware of changes in the Lambda function. Any ideas on how to ensure that the API Gateway stage is updated correctly with the new Lambda version? I'm working on a service that needs to handle this. Is there a better approach? What's the best practice here? This is happening in both development and production on Ubuntu 22.04. I'd love to hear your thoughts on this.