Reputation: 8172
I just wrote a small function which when called will return a pre-signed url for my S3 bucket. It looks like this:
import AWS from 'aws-sdk';
AWS.config.update({
accessKeyId: 'process.env.AWS_S3_KEY',
secretAccessKey: 'process.env.AWS_S3_SECRET'
});
const s3 = new AWS.S3({
signatureVersion: 'v4'
});
export const s3Auth = (req, res) => {
s3.getSignedUrl(
'putObject',
{
Bucket: 'mybucket',
Key: 'mykey',
Expires: 60
},
(error, url) => {
if (!error && url) {
res.send({
url
});
} else {
res.status(500);
res.send({ error: 'AWS error!' });
throw error;
}
}
);
};
On the third line, I have set my AWS credentials. The thing is, I tried with that part (
AWS.config.update
) commented out and it still generates the pre-signed key for me! Any idea why this is happening?
Upvotes: 0
Views: 943
Reputation: 269826
The act of generating a pre-signed URL does not actually require a call to AWS. It is simply signing a request using details of the request (eg bucket and object names) together with the Secret Key.
The URL will actually include the Access Key of the IAM entity that will be used to gain access to the object, with the signature acting as the verification that the URL is valid.
If an Access Key is appearing in your pre-signed URL, then it got the access key from somewhere -- either in a credentials file, environment variable or an IAM role assigned to the server.
Upvotes: 4
Reputation: 9411
That means you have another set of credentials defined somewhere else. Most probably:
AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
defined in your environment..aws/credentials
in your home folder.Check out all the possibilities at http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/configuring-the-jssdk.html
Upvotes: 2