Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here are the steps to set up AWS SDK in Node.js and include an IAM role:

  1. Install Node.js and NPM on your machine.
  2. Create an IAM user with the necessary permissions and save the Access Key ID and Secret Access Key.
  3. Install AWS SDK for Node.js using the command: npm install aws-sdk
  4. Create a new Node.js file and require the AWS SDK: const AWS = require('aws-sdk');
  5. Set up your AWS configuration using the Access Key ID, Secret Access Key, and region information: AWS.config.update({accessKeyId: 'ACCESS KEY ID', secretAccessKey: 'SECRET ACCESS KEY', region: 'REGION'});
  6. Create a new IAM role with the necessary permissions and save the Role ARN.
  7. Use the AWS STS service to obtain temporary AWS credentials for the IAM role: const sts = new AWS.STS(); sts.assumeRole({ RoleArn: 'ROLE ARN', RoleSessionName: 'SESSION NAME' }, function(err, data) { if (err) { console.log(err, err.stack); } else { // Use the temporary credentials to access AWS services } });
  8. Use the temporary credentials to access the necessary AWS services.

Note: Make sure to handle errors appropriately and use best practices for securing your AWS credentials.