DVA-C02 Question 286
Single answerYou are developing a serverless application using AWS Lambda functions. The code for the application is managed in a private Git repository hosted on AWS CodeCommit. You want to automate deployments of your Lambda function every time there is a new commit to the main branch in the repository. Which approach should you take to achieve this?
- A
Configure an Amazon EventBridge rule to trigger the Lambda function directly whenever a commit is pushed to the main branch.
- B
Set up an AWS CodePipeline with a source stage connected to the CodeCommit repository and a deploy stage that deploys the updated code to the Lambda function.
- C
Use a Git post-commit hook on your local machine to invoke the Lambda function and update its code whenever a commit is pushed to the main branch.
- D
Manually upload the updated code to the Lambda function each time a commit is made to the main branch in the repository.
Show answer and explanation
Correct answer: B
Explanation
The best approach to automate Lambda function deployments based on changes in a CodeCommit repository is to use AWS CodePipeline. CodePipeline integrates seamlessly with CodeCommit for source control and can include a deployment stage to automatically update the Lambda function with the latest code. This ensures a reliable and automated CI/CD process, adhering to AWS best practices.
- A. Incorrect.
Amazon EventBridge does not have a direct integration to trigger Lambda functions based on commits to a CodeCommit repository. EventBridge rules are typically used for event-driven architectures and not for automating Lambda deployments from CodeCommit.
- B. Correct.
This is the correct answer. AWS CodePipeline allows you to create a fully automated CI/CD pipeline. By configuring a source stage with CodeCommit and a deploy stage for the Lambda function, you can automate deployments whenever there is a new commit to the main branch.
- C. Incorrect.
A Git post-commit hook on a local machine is not a reliable or scalable solution for automating deployments in a distributed team or production environment. This approach also goes against AWS best practices.
- D. Incorrect.
Manually uploading code to the Lambda function is not an automated solution and does not align with modern CI/CD practices or AWS recommendations.