Quantcast
Channel: Active questions tagged amazon-ec2 - Stack Overflow
Viewing all articles
Browse latest Browse all 29258

Node.js get signedurl with AWS EC2 IAM Role Credentials

$
0
0

In my Node.js project I need to get a signed url in S3 with AWS IAM role. The part for getting the url is like this

            url = s3.getSignedUrl('getObject', {
                Bucket: myBucket,
                Key: myKey,
                Expires: signedUrlExpireSeconds
            })

And I set the values like this

var AWS = require('aws-sdk');

AWS.config.update({signatureVersion: 'v4',
region: 'us-east-1'});
AWS.config.credentials = new AWS.EC2MetadataCredentials();
var s3 = new AWS.S3();

When I run this the url I get is always just https://s3.amazonaws.com/

But if I set the credentials hard coded like this, instead of using AWS.config.credentials = new AWS.EC2MetadataCredentials();, then it returns the correct url

s3.config.update({
    accessKeyId: 'xxx',
    secretAccessKey: 'yyy',
});

According to this, https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-iam.html it should automatically get the credentials without setting like above. Can you please tell what I have done wrong and why it is not working without giving the accesskey and secrectkey directly in the code.

Also in our Java project it works fine without specifying these keys. But it is not working in Node.js.


Viewing all articles
Browse latest Browse all 29258

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>