I saw some questions on the web regarding signed S3 URLs. Those would allow someone else (not an AWS IAM user) to access S3 objects. E.g. if I have a program which has permissions to a given S3 object, I can create a signed URL which allows anyone with the knowledge of that URL to (e.g.) read the object. Or write. A simple example would be a video training web site: I could give the user a URL which is valid 24h to they can watch a video as many times as they like, but 24h only. The alternative would be the URL of the S3 object directly.
There are many ways to solve this problem, but signed URLs is what AWS offers.
Since there were so many postings and questions around this, I wondered what the problem was. The documentation at https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property certainly looked straightforward.
So a quick program created:
const AWS = require('aws-sdk') const s3 = new AWS.S3() // above is using ~/.aws/config.json to get my API key credentials // That API key inside config.json obviously has permission to the object. // A normal web browser cannot access the S3 URL ythough as the // bucket is not public. const myBucket = 'BUCKET' const myKey = 'FILE.json' const signedUrlExpireSeconds = 60 * 5 // 5min const url = s3.getSignedUrl('getObject', { Bucket: myBucket, Key: myKey, Expires: signedUrlExpireSeconds }) console.log(url)
and it all worked (AccessKeyId has access to the S3 object):
harald@blue:~/js/aws$ node sign.js https://BUCKET.s3.amazonaws.com/FILE.json?AWSAccessKeyId=AXXXXXXXXXXXXXXXXXXA&Expires=1529832632&Signature=D7eArF9AMFyWr%2FLoXcCQ0pA72i8%3D harald@blue:~/js/aws$ curl "https://BUCKET.s3.amazonaws.com/FILE.json?AWSAccessKeyId=AXXXXXXXXXXXXXXXXXXA&Expires=1529832632&Signature=D7eArF9AMFyWr%2FLoXcCQ0pA72i8%3D" { "AWSTemplateFormatVersion" : "2010-09-09", "Resources" : { [...] }
It's as easy as I thought.