0 votes
in AWS by

A company is writing a Lambda function that will run in multiple stages, such a dev, test, and production.

The function is dependent upon several external services, and it must call different endpoints for these services based on the function's deployment stage. What Lambda feature will enable the developer to ensure that the code references the correct endpoints when running in each stage?

1 Answer

0 votes
by

Answer - D.

You can create different environment variables in the Lambda function that can be used to point to the different services.

The below screenshot from the AWS Documentation shows how this can be done with databases.

Option A is invalid since this can only be used to add metadata for the function.

Option B is invalid since this is used for managing the concurrency of execution.

Option C is invalid since this is used for managing the different versions of your Lambda function.

For more information on AWS Lambda environment variables, please refer to the below Link-

https://docs.aws.amazon.com/lambda/latest/dg/env_variables.html

vy Environment variables  You can define Environment Variables as key-value pairs that are accessible from your function code. These are useful to  store configuration settings without the need to change function code. Learn more.  Database ||| Test_o8 Remove | DB_Connection | TEST Remove | Key | Value Remove

The correct answer is D. Environment variables.

AWS Lambda is a serverless compute service that allows developers to run code in response to events without provisioning or managing servers. AWS Lambda functions can be deployed in multiple stages, such as development, testing, and production, and each stage can have its own configuration settings.

In this scenario, the Lambda function depends on several external services, and it needs to call different endpoints for these services based on the function's deployment stage. To accomplish this, the developer can use environment variables.

Environment variables are key-value pairs that can be used to store configuration settings, such as API endpoint URLs, access keys, and secrets. Environment variables can be set at the function level or at the account level, and they can be accessed from within the Lambda function code.

By setting environment variables for each stage of the function, the developer can ensure that the function references the correct endpoints when running in each stage. For example, the developer could set the API endpoint URL for the development stage as an environment variable named DEV_API_ENDPOINT_URL, and set the API endpoint URL for the production stage as an environment variable named PROD_API_ENDPOINT_URL. The Lambda function code could then reference the appropriate environment variable to determine the correct API endpoint to call.

In summary, environment variables are a powerful feature of AWS Lambda that can be used to store configuration settings for each stage of a function's deployment. By using environment variables to store endpoint URLs and other settings, developers can ensure that their Lambda function code references the correct endpoints for each stage.

...