I am very new to serverless and lambda functions. I have an application where I need to use the S3 service. When I test credentials created manually in my AWS account, I can access these services. However, when I try to use it from serverless, I am encountering this issue: InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.
**serverless.yaml **
org: juan
app: knot
service: knot-be
provider:
environment:
APP_ENV: staging
...... env variables.....
name: aws
runtime: nodejs18.x
region: us-east-1
apiGateway:
binaryMediaTypes:
- "*/*"
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:*"
Resource: "arn:aws:s3:::knot-be/*"
- Effect: "Allow"
Action:
- "ses:SendEmail"
- "ses:SendRawEmail"
Resource: "*"
- Effect: "Allow"
Action:
- "rds:*"
Resource: "*"
ecr:
images:
appimage:
path: ./
functions:
api:
image:
name: appimage
command:
- dist/lambda.handler
entryPoint:
- '/lambda-entrypoint.sh'
timeout: 30
events:
- http:
path: /{proxy+}
method: any
- http:
path: /
method: any
resources:
Resources:
Bloodknot3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: knot-be
plugins:
- serverless-offline
**this is my s3.config.ts **
const s3Config = {
bucketName: process.env.AWS_S3_BUCKET_NAME || 'bloodknot-storage-dev',
region: (process.env.AWS_REGION || 'us-east-2') as BucketLocationConstraint,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID || '',
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || '',
},
}
const s3Client = new S3Client(s3Config)
export {
s3Config,
GetObjectCommand,
PutObjectCommand,
DeleteObjectCommand,
ListObjectsV2Command,
S3Client,
getSignedUrl,
}
export default s3Client
And I created an endpoint to check if I have available AWS variables and ofcourse I have them in a response from the deploy server:
{ "bucketName": "knot-be", "region": "us-east-1", "credentials": { "accessKeyId": "ASIA.....", "secretAccessKey": "qG....." } }
But i’m still having the same issue, even if I try this in the server or with local variables:
[Nest] 5538 - 05/07/2024, 1:00:21 AM ERROR [S3StorageProvider] InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.
[Nest] 5538 - 05/07/2024, 1:00:21 AM ERROR [ExceptionsHandler] Error uploading file at 6b613615-af7b-4408-8566-89e9a5f08872
Error: Error uploading file at 6b613615-af7b-4408-8566-89e9a5f08872
at S3StorageProvider.uploadFile (/home/seb/Desktop/knotblood/bloodknot-backend/src/commons/providers/file-storage/s3/s3-storage.provider.ts:125:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.all (index 0)
Why does it work on my local machine when I use my own AWS variables, but I still get this error when I use serverless variables, even if I use them locally too? Is there something I’m doing wrong with my serverless file, or is there some additional configuration I need to do in AWS to use this with serverless?
I hope the application works because when I use variables that I create manually, the whole system works. However, when it’s from serverless, nothing works and it just generates this error.
Sebastian Rodriguez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.