Here are the steps to set up AWS SDK in Node.js and include an IAM role:
- Install Node.js and NPM on your machine.
- Create an IAM user with the necessary permissions and save the Access Key ID and Secret Access Key.
- Install AWS SDK for Node.js using the command: npm install aws-sdk
- Create a new Node.js file and require the AWS SDK: const AWS = require('aws-sdk');
- 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'});
- Create a new IAM role with the necessary permissions and save the Role ARN.
- 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 } });
- 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.