What is it for? I cannot reproduce this problem. I created a new instance of EC2, assigned it an IAM role in which AmazonS3FullAccess permission is allowed
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "s3:*", "Resource": "*" } ] }
The earliest version of Python I could install was 2.7.12 with Boto 2.38.0
[ root@ip-172-31-13-14 ~]
Then I run the app.py code
from boto.s3.connection import S3Connection def get_signed_upload_url(): BUCKET = 'test' KEY = 'test-2' s3 = S3Connection(is_secure=True) return s3.generate_url(300, 'PUT', bucket=BUCKET, key=KEY, headers={'Content-Type': 'text/plain'}) if __name__ == "__main__": url = get_signed_upload_url() print "curl -v -X PUT -H 'Content-Type: text/plain' -d @hello2.txt '" + url + "'"
Then run the resulting cURL command and the file will load successfully.
> Host: test.s3.amazonaws.com > User-Agent: curl/7.53.1 > Accept: */* > Content-Type: text/plain > Content-Length: 8585 > Expect: 100-continue > < HTTP/1.1 100 Continue * We are completely uploaded and fine < HTTP/1.1 200 OK < x-amz-id-2: redacted < x-amz-request-id: redacted < Date: Tue, 19 Dec 2017 05:45:15 GMT < x-amz-version-id: redacted < ETag: "redacted" < Content-Length: 0 < Server: AmazonS3
At this point, I can only guess that perhaps the IAM role you are using does not have sufficient privileges to perform the PUT action? Otherwise, there may be a difference in how your client-side code actually executes the PUT request, but this is unlikely.
Other things to check:
- Verify that the time on the EC2 instance is accurate.
- Verify that the AWS_REGION environment variable is set
source share