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

(aws-lambda): docker image function fails with insightsVersion property #16642

Closed
jaypea opened this issue Sep 24, 2021 · 2 comments · Fixed by #16781
Closed

(aws-lambda): docker image function fails with insightsVersion property #16642

jaypea opened this issue Sep 24, 2021 · 2 comments · Fixed by #16781
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@jaypea
Copy link

jaypea commented Sep 24, 2021

when using a DockerImageFunction and trying to enable cloudwatch lambda insights through the insightsVersion property, lambda service fails to create the function with error:

1:08:45 PM | CREATE_FAILED        | AWS::Lambda::Function                     | lambda8B5974B5
Resource handler returned message: "Lambda layers are not supported for functions created with container images. (Service: Lambda, Status Code: 400, Request ID: 0526411c-a65a-485e-8582-fe2f2ec4ff90, Extended Request ID: null)" (RequestToken: 283267a3-b4
80-d004-54bc-f83f3c52fde7, HandlerErrorCode: InvalidRequest)

	new Function (/home/code/node_modules/@aws-cdk/aws-lambda/lib/function.ts:373:35)
	\_ new DockerImageFunction (/home/code/node_modules/@aws-cdk/aws-lambda/lib/image-function.ts:44:5)

Reproduction Steps

const appHandler = new DockerImageFunction(this, 'lambda', {
      code: DockerImageCode.fromImageAsset(path.join(__dirname, '../../')),
      insightsVersion: LambdaInsightsVersion.VERSION_1_0_98_0,
    });

What did you expect to happen?

to skip adding a layer and just manage the execution role instead

What actually happened?

creation failed

Environment

  • CDK CLI Version : 1.124.0 (build 65761fe)
  • Framework Version:
  • Node.js Version: 14
  • OS : linux
  • Language (Version): typescript

Other

my first idea to fix this would be to overwrite the configureLambdaInsights method in the DockerImageFunction Class and just add the manged policy there and skip the addLayers part.


This is 🐛 Bug Report

@jaypea jaypea added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 24, 2021
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Sep 24, 2021
@jaypea
Copy link
Author

jaypea commented Sep 28, 2021

if someone needs a workaround, skip the property in the DockerImageFunction and add the policy like this:

    const appHandler = new DockerImageFunction(this, 'lambda', {
      code: DockerImageCode.fromImageAsset(path.join(__dirname, '../../')),      
    });
    appHandler.role?.addManagedPolicy(
      ManagedPolicy.fromAwsManagedPolicyName(
        'CloudWatchLambdaInsightsExecutionRolePolicy'
      )
    );

the docker image needs the lambda-insights-extension in any case

FROM public.ecr.aws/lambda/python:3.9

RUN curl -O https://lambda-insights-extension.s3-ap-northeast-1.amazonaws.com/amazon_linux/lambda-insights-extension.rpm && \
  rpm -U lambda-insights-extension.rpm && \
  rm -f lambda-insights-extension.rpm

@nija-at nija-at added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Oct 4, 2021
nija-at pushed a commit that referenced this issue Oct 4, 2021
…ified

Lambda insights is configured as a set of layers that are then
auto-added to the lambda function when the `insightsVersion` property is
specified.

However, Lambda functions deployed as container images cannot contain
layers. Instead, the user is expected to bring a container image with
the Insights agent pre-installed.

Update the CDK code, so that the layer is not added for Lambda functions
that use container images.

fixes #16642
@mergify mergify bot closed this as completed in #16781 Oct 14, 2021
mergify bot pushed a commit that referenced this issue Oct 14, 2021
…ified (#16781)

Lambda insights is configured as a set of layers that are then
auto-added to the lambda function when the `insightsVersion` property is
specified.

However, Lambda functions deployed as container images cannot contain
layers. Instead, the user is expected to bring a container image with
the Insights agent pre-installed.

Update the CDK code, so that the layer is not added for Lambda functions
that use container images.

fixes #16642


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…ified (aws#16781)

Lambda insights is configured as a set of layers that are then
auto-added to the lambda function when the `insightsVersion` property is
specified.

However, Lambda functions deployed as container images cannot contain
layers. Instead, the user is expected to bring a container image with
the Insights agent pre-installed.

Update the CDK code, so that the layer is not added for Lambda functions
that use container images.

fixes aws#16642


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants