AWS Certified Developer – Associate / Question #622 of 557

Question #622

A developer is building a new application on AWS. The application uses an AWS Lambda function that invokes an Amazon API Gateway API. The developer hard coded the API Gateway URL into the Lambda function code. The URL might change over time.

The developer does not want to modify the Lambda code if the URL changes.

Which solution will meet these requirements MOST efficiently?

A

Create a Lambda environment variable to store the API Gateway URL. Use the standard method for the programming language to retrieve the variable.

B

Store the API Gateway URL in a file. Store the file in the /tmp folder. Use the SDK for the programming language to retrieve the URL.

C

Create a file to store the API Gateway URL. Zip the file and upload it to the Lambda layer. Use the SDK for the programming language to retrieve the URL.

D

Create a global variable that is outside the handler in the Lambda function to store the API Gateway URL.

Explanation

The correct answer is A because Lambda environment variables provide a straightforward way to externalize configuration like the API Gateway URL. When the URL changes, updating the environment variable in the Lambda configuration suffices, avoiding code changes. Options B and C involve file storage, which introduces complexity (e.g., ephemeral /tmp storage or managing layers). Option D uses a global variable, which still requires code changes if the URL changes. Environment variables are the most efficient and scalable solution, ensuring separation of configuration from code.

Answer

The correct answer is: A