My application is an AWS Lambda which uses v3 of the AWS-SDK.
The purpose of my Lambda is to read from a DynamoDB table which holds the AWS secret key and access key of a customer, I then want to use the AWS-SDK to call the describeVpcs with the information retrieved from DynamoDB.
I can see the use of passing the access key and secret key into the AWS.config.update
as been deprecated.
My code below will gather information about the VPCs in my AWS account rather than the customers. I am looking for the alteration needed to use the customers information.
const { EC2 } = require('@aws-sdk/client-ec2');
const ec2 = new EC2();
const describeVpcs = async () => {
const params = {
};
try {
const data = await ec2.describeVpcs(params);
return data;
} catch (e) {
console.error(e);
throw new Error(e);
}
};
module.exports = { describeVpcs };
2
Answers
For your Lambda to have access to
describeVpcs
, you will need your lambda to assume a role in the other account. Basically, you need to create a role in the other account with the needed access, and you allow your Lambda to assume said role. You could follow this tutorial: https://aws.amazon.com/premiumsupport/knowledge-center/lambda-function-assume-iam-role/you can try pass credentials like: