Problems with aws role switching using the aws-sdk?
Automatically assume appropriate aws role based on your AWS_PROFILE env varriable.
Install
npm i aws-auto-assume-role
without touching your code
AWS_PROFILE=my_aws_project node -r aws-auto-assume-role app.js
with touching your code (require yourself)
const autoAssume = require('aws-auto-assume-role')
autoAssume(() => {
const AWS = require('aws-sdk')
const DocumentClient = AWS.DynamoDB.DocumentClient
const ddb = new DocumentClient({ region: process.env.AWS_REGION })
const params = {
TableName: 'my-table',
Key: {
id
}
}
ddb.get(params, (err, res) => {
console.log(err)
console.log(res)
})
})
require('aws-auto-assume-role').sync();
const AWS = require('aws-sdk')
const DocumentClient = AWS.DynamoDB.DocumentClient
const ddb = new DocumentClient({ region: process.env.AWS_REGION })
const params = {
TableName: 'my-table',
Key: {
id
}
}
ddb.get(params, (err, res) => {
console.log(err)
console.log(res)
})