Comments for Upload a File to S3

#81

Hmm in this case we are only allowing authenticated users to upload to the S3 bucket.

#82

Was getting 403 access denied during file upload, for IdentityPoolAuth_role with the policy mentioned in chapter IdentityPoolAuth_role Policy

Had to change the policy to the one mentioned in iam-roles for file upload to work.

#83
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": ["s3:ListBucket"],
      "Effect": "Allow",
      "Resource": ["arn:aws:s3:::mybucket"],
      "Condition": {"StringLike": {"s3:prefix": ["${cognito-identity.amazonaws.com:sub}/*"]}}
    },
    {
      "Action": [
        "s3:GetObject",
        "s3:PutObject"
      ],
      "Effect": "Allow",
      "Resource": ["arn:aws:s3:::mybucket/private/${cognito-identity.amazonaws.com:sub}/*"]
    }
  ]
}
#84

Thanks for reporting back!

1 Like
#85

Hey @jayair, I found a weird behaviour in this chapter. In the createNote function, the body of the note only gets sent to DDB if I pass the object {body: note} (instead of {body: note.content}, which is weird because that is a whole object and not just the string we want. It does work as intended, if written like this, like you did before the file upload. Any clues why?

#86

Hmm can you paste the code you are referring to?

#87

Nevermind @jayair I’m dumb ahah. Thanks anyway man!

#88

tl;dr For config.js don’t use the S3 bucket name you manually created. Use the bucket name that’s created automatically with the Serverless command.

If you’re like me you’ve come here looking for answers as to why you keep getting an error (ie. CORB & No ‘Access-Control-Allow-Origin’) when trying to upload a file to S3 when you’ve followed all the instructions up to now to a T.

It appears that the S3 Bucket that we create here is not the same as the one created here (using the Serverless setup from the chapter, add-support-for-es6-es7-javascript). If you head over to AWS and checkout your S3 Bucket you’ll see the bucket you created plus an additional one that was created when you ran the Serverless command. For me I had “notes-app-uploads-v01” and “notes-app-api-prod-serverlessdeploymentbucket-1c3wwxszxsnup”. Yours will differ slightly. In any case there are two different buckets. Don’t make the same mistake I made and delete the long worded one. In fact keep it and use that name to populate the bucket name in config.js.

Hopefully this will save someone minutes/hours of frustration.

1 Like
#89

Thanks for the details @mikeyamato! I’m sure it’ll be helpful to others.