I am getting AccessDenied: Access Denied
while upload files to my s3 bucket
. But everything is working perfectly locally
.
This is the error I am seeing in my cloudwatch
AccessDenied: Access Denied
api
at throwDefaultError (/app/node_modules/@aws-sdk/client-s3/node_modules/@smithy/smithy-client/dist-cjs/index.js:838:20)
api
at /app/node_modules/@aws-sdk/client-s3/node_modules/@smithy/smithy-client/dist-cjs/index.js:847:5
api
at de_CommandError (/app/node_modules/@aws-sdk/client-s3/dist-cjs/index.js:4748:14)
api
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
api
at async /app/node_modules/@aws-sdk/client-s3/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20
api
at async /app/node_modules/@aws-sdk/middleware-signing/dist-cjs/index.js:226:18
api
at async /app/node_modules/@aws-sdk/client-s3/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38
api
at async /app/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js:174:18
api
at async /app/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:98:20
api
at async /app/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:121:14 {
api
'$fault': 'client',
api
'$metadata': {
api
httpStatusCode: 403,
api
requestId: 'Y9W345675765774JW',
api
extendedRequestId: 'LW2UXs3455646hiFZs0b/mU0UNisiXAfsdff43fdsgHOUH8s51OJklhRNU=',
api
cfId: undefined,
api
attempts: 1,
api
totalRetryDelay: 0
api
},
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.
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!
2