A developer is writing a Node.js application that uses the AWS SDK for JavaScript to read data from an Amazon DynamoDB table. The application must run on the developer's local workstation during development and on an AWS Lambda function in the production environment. Which two configurations should the developer use to manage credentials securely and ensure the application works in both environments without code modifications?
- AInitialize the DynamoDB client by passing the AWS access key and secret key directly to the constructor in the application code.
- Configure the credentials in the shared credentials file (~/.aws/credentials) on the local workstation, and assign an IAM execution role with DynamoDB access permissions to the Lambda function.Cevap
- Instantiate the DynamoDB client using the default constructor without passing explicit credentials.Cevap
- DPackage a local configuration file containing the developer's AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY directly inside the Lambda deployment package.
- EStore the developer's long-lived IAM access keys in AWS Secrets Manager, and configure the application to query Secrets Manager at startup to retrieve credentials.
Cevap
Configure credentials in the shared credentials file (~/.aws/credentials) on the local workstation, assign an IAM execution role with DynamoDB access permissions to the Lambda function, and instantiate the DynamoDB client using the default constructor without passing explicit credentials.
The correct approach involves configuring the developer's credentials locally in the shared credentials file, assigning an IAM execution role to the Lambda function, and instantiating the SDK client using the default constructor. When initialized without credentials, the AWS SDK default credential provider chain looks for credentials dynamically. On the local workstation, the SDK resolves credentials from the shared credentials file. On Lambda, the SDK automatically retrieves temporary security credentials from the IAM execution role via environment variables.
Adım Adım Çözüm
Anahtar Kavram
AWS SDK Default Credential Provider Chain