Amazon S3 file download through curl using IAM user credentials

I created an IAM user with access to only one bucket. I checked credentials and permissions via web and python boto. It works great.

Now I have a requirement to use these credentials and load a personal file from this bucket through curl .

 signature="$(echo -n "GET" | openssl sha1 -hmac "f/rHQ8yCvPthxxxxxxxXxxxx" -binary | base64)" date="$(LC_ALL=C date -u +"%a, %d %b %Y %X %z")" curl -H "Host: my-bucket.s3.amazonaws.com" -H "Date: $date" -H "Authorization: AWS 'XXXAJX2NY3QXXX35XXX':$signature" -H "Content-Type: 'text/plain'" https://my-bucket.s3.amazonaws.com/path/to_file.txt 

but I get the following error:

<Code> InvalidAccessKeyId The AWS passkey identifier that you specified does not exist in our records.

Please help how to upload a file using curl ? Is there something I can't see, or is it impossible with the curl command?

Thanks!

+7
source share
1 answer

Below is an example of how you can download using s3 curl script,

 #!/bin/sh file=path/to/file bucket=your-bucket resource="/${bucket}/${file}" contentType="application/x-compressed-tar" dateValue="`date +'%a, %d %b %Y %H:%M:%S %z'`" stringToSign="GET ${contentType} ${dateValue} ${resource}" s3Key=xxxxxxxxxxxxxxxxxxxx s3Secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx signature=`/bin/echo -en "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64` curl -H "Host: ${bucket}.s3.amazonaws.com" \ -H "Date: ${dateValue}" \ -H "Content-Type: ${contentType}" \ -H "Authorization: AWS ${s3Key}:${signature}" \ https://${bucket}.s3.amazonaws.com/${file} 

Hope this helps.

0
source

Source: https://habr.com/ru/post/982592/


All Articles