aws / aws/aws-cdk

lambda : Error deploying docker lambda function

Open
#26,372 4 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-lambda bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
74

Description

### Describe the bug

I am trying to deploy a dockerized lambda function.

This is my code:

```ts
const leaderboardsStreamHandler = new lambda.Function(this, 'leaderboardsStreamHandler', {
functionName: 'leaderboardsStreamHandler',
code: lambda.Code.fromDockerBuild(path.resolve('resources/lambdas-code/leaderboardsStreamHandler')),
handler: lambda.Handler.FROM_IMAGE,
runtime: lambda.Runtime.FROM_IMAGE,
environment: {
'TABLE_NAME': props.leaderboardsTable.tableName,
'STAGE': props.STAGE.toLowerCase()
},
logRetention: RetentionDays.ONE_WEEK,
description: 'Lambda function responsible for inserting participants in the Leaderboards table'
})
```

The Image build completes succesfully, but I get the error reported below:

Why is this happening? It doesn't make any sense :/

### Expected Behavior

I am following the documentation, so it should work just fine TBH

### Current Behavior

I get the following error:

```
Error: handler must be `Handler.FROM_IMAGE` when using image asset for Lambda function
at verifyCodeConfig (/home/ettore/Documents/Innovyou/Qlash/leaderboards/node_modules/aws-cdk-lib/aws-lambda/lib/function.js:1:22156)
at new Function (/home/ettore/Documents/Innovyou/Qlash/leaderboards/node_modules/aws-cdk-lib/aws-lambda/lib/function.js:1:7490)
at new LeaderboardsStreamLambdaStack (/home/ettore/Documents/Innovyou/Qlash/leaderboards/lib/lambdas/leaderboards-stream-lambda-stack.ts:19:43)
at Object. (/home/ettore/Documents/Innovyou/Qlash/leaderboards/bin/leaderboards.ts:38:1)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module.m._compile (/home/ettore/Documents/Innovyou/Qlash/leaderboards/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Object.require.extensions. [as .ts] (/home/ettore/Documents/Innovyou/Qlash/leaderboards/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Function.Module._load (node:internal/modules/cjs/loader:958:12)

Subprocess exited with error 1

```

### Reproduction Steps

cdk deploy

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.87

### Framework Version

_No response_

### Node.js Version

v18.04

### OS

Linux - Ubuntu

### Language

Typescript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with cdk deploy using the stack trace entry points lib/lambdas/leaderboards-stream-lambda-stack.ts and bin/leaderboards.ts. Then inspect aws-lambda's verifyCodeConfig behavior for the Docker-built code and compare it with the documented configuration; done means the deployment succeeds or the required configuration is clearly documented and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.