Skip to Content

DVA-C02: How to Dynamically Reference DynamoDB Table Name in AWS Lambda Function

Learn how to dynamically reference DynamoDB table name in AWS Lambda function without hard coding it. Find out the best solution for this common challenge faced by AWS developers.

Table of Contents

Question

A developer is building a new application on AWS. The application uses an AWS Lambda function that retrieves information from an Amazon DynamoDB table. The developer hard coded the DynamoDB table name into the Lambda function code. The table name might change over time. The developer does not want to modify the Lambda code if the table name changes.

Which solution will meet these requirements MOST efficiently?

A. Create a Lambda environment variable to store the table name. Use the standard method for the programming language to retrieve the variable.

B. Store the table name in a file. Store the file in the /tmp folder. Use the SDK for the programming language to retrieve the table name.

C. Create a file to store the table name. Zip the file and upload the file to the Lambda layer. Use the SDK for the programming language to retrieve the table name.

D. Create a global variable that is outside the handler in the Lambda function to store the table name.

Answer

A. Create a Lambda environment variable to store the table name. Use the standard method for the programming language to retrieve the variable.

Explanation

The correct answer is A. Create a Lambda environment variable to store the table name. Use the standard method for the programming language to retrieve the variable.

The reason is that Lambda environment variables are key-value pairs that can be used to store configuration settings or sensitive data for a Lambda function. Lambda environment variables can be accessed by using the standard method for the programming language, such as process.env in Node.js or os.environ in Python. Lambda environment variables can be modified without changing the Lambda code, which makes them suitable for storing the DynamoDB table name that might change over time.

The other options are incorrect because they are not efficient or secure:

B. Storing the table name in a file and storing the file in the /tmp folder is not efficient or secure. The /tmp folder is a temporary storage space that is shared by all the concurrent executions of the same Lambda function. The file might be overwritten or deleted by another execution, which can cause errors or inconsistencies. Moreover, the /tmp folder is not encrypted, which can expose sensitive data.

C. Storing the table name in a file and uploading the file to the Lambda layer is not efficient. A Lambda layer is a ZIP archive that contains libraries, dependencies, or other resources that can be shared by multiple Lambda functions. A Lambda layer is read-only and cannot be modified at run time, which means that the developer will have to create a new layer and update the function configuration every time the table name changes.

D. Storing the table name in a global variable that is outside the handler in the Lambda function is not efficient or secure. A global variable is a variable that is declared outside any function and can be accessed by any function in the same module. A global variable can retain its value between invocations of the same Lambda function instance, which can cause errors or inconsistencies if the table name changes. Moreover, a global variable is not encrypted, which can expose sensitive data.

The latest AWS Certified Developer – Associate DVA-C02 certification actual real practice exam question and answer (Q&A) dumps are available free, which are helpful for you to pass the AWS Certified Developer – Associate DVA-C02 exam and earn AWS Certified Developer – Associate DVA-C02 certification.

AWS Certified Developer - Associate DVA-C02 Exam Questions and Answers