A few things you need to make sure you have done:
- Need to make sure the user creating the presigned key has the ability to call PutObject on the target bucket
- Need to make sure the bucket as the correct CORS on it
In my use case I am using "serverless.com" - in serverless, it would look like this
provider:
name: aws
stage: ${opt:stage, 'dev'}
region: RRRR
runtime: nodejs10.x
profile: XXXX
iamRoleStatements:
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
Resource:
- "arn:aws:s3:::${self:custom.buckets.${self:custom.stage}}/*"
- Effect: Allow
Action:
- s3:ListBucket
Resource:
- "arn:aws:s3:::${self:custom.buckets.${self:custom.stage}}*"
BUCKETNAME=mybucket
aws --profile=XXXX s3api put-bucket-cors --bucket $BUCKETNAME --cors-configuration '{"CORSRules": [{"AllowedOrigins": ["*"], "AllowedMethods": ["PUT"], "AllowedHeaders": ["*"]}]}'
After you have the presigned URL you can upload to test via curl:
URL=[PRE_SIGNED_URL]
curl -X PUT -H "Content-Type: image/jpeg" -T picture.jpg $URL