AWS Certified Developer – Associate — Question 18
A developer is creating an AWS Lambda function that generates a new file each time it runs. Each new file must be checked into an AWS CodeCommit repository hosted in the same AWS account.
How should the developer accomplish this?
Answer options
- A. When the Lambda function starts, use the Git CLI to clone the repository. Check the new file into the cloned repository and push the change.
- B. After the new file is created in Lambda, use cURL to invoke the CodeCommit API. Send the file to the repository.
- C. Use an AWS SDK to instantiate a CodeCommit client. Invoke the putjile method to add the file to the repository.
- D. Upload the new file to an Amazon S3 bucket. Create an AWS Step Function to accept S3 events. In the Step Function, add the new file to the repository.
Correct answer: C
Explanation
The correct answer is C because using an AWS SDK to create a CodeCommit client allows for direct interaction with the repository, making it easy to add files through the putfile method. Option A is inefficient as it involves cloning the repository and handling Git commands, which is not ideal for Lambda functions. Option B incorrectly suggests using cURL, which is not necessary when an SDK is available. Option D introduces unnecessary complexity by using S3 and Step Functions, which is not needed for directly adding files to CodeCommit.