S3 error undefined (reading byteLength) for AWS AMPLIFY

Viewed 777

I keep getting a TypeError: Cannot read properties of undefined (reading 'byteLength') Error when using AWS with Amplify.

It looks like the s3 bucket permissions were not created properly when I added the s3 through the Amplify CLI.

When I add the sample s3 bucket policy from https://docs.amplify.aws/lib/storage/getting-started/q/platform/js/

It still does not work.

AWSS3Provider - get signed url error TypeError: Cannot read properties of undefined (reading 'byteLength')

My Code to call it:

const res = await Storage.get("test.json");

This includes any Storage.list, Storage.put commands.

enter image description here

This leads me to believe it has trouble getting the key from storage. I have done it all through the cli which is puzzling.

1 Answers

When I add the sample s3 bucket policy
Question is: What do I add for the principal for an authenticated user? Does anyone have a sample?

The policies mentioned are to be attached to the IAM cognito roles Auth_Role and Unauth_Role (or however are the roles for the cognito users named) not the S3 bucket. Then the principal is the IAM role itself.

In theory you may attach the defined policies to the S3 bucket and define the principals as the Cognito roles for the authenticated and unauthenticated users

Related