I want to create a CloudFormation stack. It creates all the resources inside the template. But when it comes to lambda functions it fails with the error message:
Resource handler returned message: "Error occurred while GetObject. S3 Error Code: NoSuchKey. S3 Error Message: The specified key does not exist. (Service: Lambda, Status Code: 400, Request ID: cdfeb740-263c-4b0a-9ef3-7adf63ccbfce)" (RequestToken: e57fb400-10d2-aaee-8a56-011125a20a53, HandlerErrorCode: InvalidRequest)
Here's a piece from the template:
ServerlessDeploymentBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
AuthorizerLambdaFunction:
Type: 'AWS::Lambda::Function'
Properties:
Code:
S3Bucket: !Ref ServerlessDeploymentBucket
S3Key: >-
serverless/sensor-processor-v3/dev/1689595670583-2023-07-17T12:07:50.583Z/sensor-processor-v3.zip
Handler: src/authorizer.handler
Runtime: nodejs18.x
FunctionName: sensor-processor-v3-dev-authorizer
MemorySize: 128
Timeout: 30
Environment:
Variables:
STAGE: dev
The message says that the error occurred while GetObject. Here's the only part where getobject mentioned
IamRoleLambdaExecution:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: !Join
- '-'
- - sensor-processor-v3
- dev
- lambda
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'lambda:InvokeFunction'
Resource: '*'
- Effect: Allow
Action:
- 's3:GetObject'
- 's3:ListBucket'
- 's3:PutObject'
I looked inside serverless/sensor-processor-v3/dev/1689595670583-2023-07-17T12:07:50.583Z/sensor-processor-v3.zip
this file (Actually not this one, but prod version of this). The zip
file contains the compiled javascript version of the code.
- Should I create the bucket and deploy my code there manually?
- Cloudformation should create the bucket automatically. Am I right?
- The source code is deployed to GitLab. Where did the compiled jaavscript version of the come from?