AWS Certified Developer – Associate / Question #937 of 557

Question #937

A company uses AWS CloudFormation to manage an Amazon API Gateway REST API deployed via AWS CodePipeline. The CloudFormation template includes resources for AWS::ApiGateway::RestApi, Resource, Method, Stage, and Deployment. After modifying the template to add a new method and redeploying, the stack update completes successfully, but the new method returns a 404 error. What should the developer do to resolve this issue?

A

Include the --no-fail-on-empty-changeset parameter in the CloudFormation deployment command.

B

Modify the AWS::ApiGateway::Stage resource to explicitly reference the latest Deployment ID.

C

Integrate an AWS CodeBuild stage into CodePipeline to execute the aws apigateway create-deployment CLI command.

D

Add a CodePipeline action to invalidate the API Gateway cache using the AWS CLI.

Explanation

When updating an API Gateway via CloudFormation, the Deployment resource must be explicitly triggered to apply changes to a stage. CloudFormation may not automatically create a new deployment if the Deployment resource's properties remain unchanged, even if underlying API resources (e.g., Methods) are modified. This results in the stage not reflecting the latest changes, causing 404 errors.

Correct Answer (C): Integrating CodeBuild to run 'aws apigateway create-deployment' ensures a new deployment is created, updating the stage with the latest API configuration.

Why Others Are Incorrect:
- A: The '--no-fail-on-empty-changeset' parameter avoids failure when no changes exist, which isn't the issue here.
- B: Explicitly referencing the Deployment ID in the Stage requires dynamic updates to the template, which isn't automated in the given setup.
- D: Cache invalidation addresses cached responses, not undeployed methods causing 404s.

Key Takeaway: Always ensure API Gateway deployments are explicitly triggered after CloudFormation updates to propagate changes to stages.

Answer

The correct answer is: C