Skip to content

Access denied 403 Error while uploading to S3 bucket in production (Working locally)

0

I am getting AccessDenied: Access Denied while upload files to my s3 bucket. But everything is working perfectly locally. I also checked the permissions in IAM and I have given s3 full access.

I thought there must be some issue with the env not being fetched properly so I logged everything. All the env are being fetched properly. Why is it only not working in production, I am really confused since it is working locally.

This is the error I am seeing in my cloudwatch :

**AccessDenied: Access Denied**
at throwDefaultError (/app/node_modules/@aws-sdk/client-s3/node_modules/@smithy/smithy-client/dist-cjs/index.js:838:20)
at async /app/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:121:14 {
'$fault': 'client',
'$metadata': {
httpStatusCode: 403,
requestId: 'Y9W345675765774JW',
extendedRequestId: 'LW2UXs3455646hiFZs0b/mU0UNisiXAfsdff43fdsgHOUH8s51OJklhRNU=',
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},

I have also enabled CORS for :

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "POST",
            "PUT",
            "DELETE",
            "HEAD"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": []
    }
]
1 Answer
1
Accepted Answer

This is very important and will be useful to future developers who are stuck in this same situation.

Since I was using ECS Fargate, I had to add s3 permissions for ecsTaskRole.

This role is the one which you will be using while creating your task definition. "Task role" to be exact.

Go to IAM > Roles > Select "ecsTaskRole" (Create one if you haven't) > Permissions policies > Add required S3 permissions (I added AmazonS3FullAccess).

And it worked!

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.