Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lambda : Error deploying docker lambda function #26372

Open
ETisREAL opened this issue Jul 14, 2023 · 4 comments
Open

lambda : Error deploying docker lambda function #26372

ETisREAL opened this issue Jul 14, 2023 · 4 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@ETisREAL
Copy link

ETisREAL commented Jul 14, 2023

Describe the bug

I am trying to deploy a dockerized lambda function.

This is my code:

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.<anonymous> (/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.<computed> [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

@ETisREAL ETisREAL added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 14, 2023
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Jul 14, 2023
@pahud pahud self-assigned this Jul 14, 2023
@pahud
Copy link
Contributor

pahud commented Jul 14, 2023

For lambda container runtime, I think you should use DockerImageFunction instead.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 14, 2023
@pahud pahud removed their assignment Jul 14, 2023
@pahud pahud added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 14, 2023
@ETisREAL
Copy link
Author

No, that's not it. DockerImageFunction is what I should use if I already have the image pushed to ECR. In this case I ma trying to build it on deployment

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 15, 2023
@pahud
Copy link
Contributor

pahud commented Jul 17, 2023

@ETisREAL DockerImageFunction allows you to specify DockerImageCode for the code property. And you can specify your local docker assets directory with fromImageAssets. On cdk synth, the docker image assets will be built with docker build from the path you specify and published to the staging ECR repo. Is this something you expect?

@pahud pahud added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 17, 2023
@ETisREAL
Copy link
Author

@pahud As the fllowing code I suppose: new lambda.DockerImageFunction(this, 'leaderboardsStreamHandler', { functionName: 'leaderboardsStreamHandler', code: lambda.DockerImageCode.fromImageAsset(path.resolve('resources/lambdas-code/leaderboardsStreamHandler/code')), environment: { 'TABLE_NAME': props.leaderboardsTable.tableName, 'STAGE': props.STAGE.toLowerCase() }, events: [ new lambda_event_sources.DynamoEventSource(props.leaderboardsTable, { startingPosition: lambda.StartingPosition.TRIM_HORIZON, retryAttempts: 2, batchSize: 1, filters: [ lambda.FilterCriteria.filter({ dynamodb: { Keys: { PK: {S: lambda.FilterRule.beginsWith('PARTICIPANT#')}, SK: {S: lambda.FilterRule.beginsWith('#TOURNAMENT#')} } } }) ] }) ], logRetention: RetentionDays.ONE_WEEK, description: 'Lambda function responsible for creating and updating leaderboards' })

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants