Skip to content

(aws-lambda): lambda does not set environment variable AWS_CODEGURU_PROFILER_GROUP_NAME when creating Amazon CodeGuru Profiler profiling group #23511

@tfcerda

Description

@tfcerda

Describe the bug

When setting { profiling: true }, the CDK creates a Profiling Group with an autogenerated name. This name is never set to AWS_CODEGURU_PROFILER_GROUP_NAME environment variable as stated in the official docs. This causes the Lambda to create another profiling group with a default name aws-lambda-<LAMBDA_FUNCTION_NAME>. Therefore, the Lambda runs into permissions issues when submitting profiles, as the CDK does not create permissions to submit to aws-lambda-<LAMBDA_FUNCTION_NAME>.

Expected Behavior

When setting { profiling: true }, Lambda submits profiles to Profiling Group created by CDK.

Current Behavior

When setting { profiling: true }, Lambda fails with permissions issues. Example errors:

INFO: Could not find a profiling group name from environment variable AWS_CODEGURU_PROFILER_GROUP_NAME. Using default profiling group name aws-lambda-<LAMBDA_FUNCTION_NAME>

codegurushadow.software.amazon.awssdk.services.codeguruprofiler.model.CodeGuruProfilerException: User: <USER_ARN> is not authorized to perform: codeguru-profiler:ConfigureAgent on resource: arn:aws:codeguru-profiler:<REGION>:<AWS_ACCOUNT_ID>:profilingGroup/aws-lambda-<LAMBA_FUNCTION_NAME> (Service: CodeGuruProfiler, Status Code: 403, Request ID: <REQUEST_ID>)

Reproduction Steps

Create Lambda function with Java runtime and { profiling: true }

Possible Solution

Set AWS_CODEGURU_PROFILER_GROUP_NAME: props.profilingGroup.profilingGroupName in

profilingGroupEnvironmentVariables = {

and AWS_CODEGURU_PROFILER_GROUP_NAME: profilingGroup.profilingGroupName in

profilingGroupEnvironmentVariables = {

Additional Information/Context

No response

CDK CLI Version

1.186.0 and 2.58.0

Framework Version

No response

Node.js Version

18.11.0

OS

MacOS

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Labels

@aws-cdk/aws-lambdaRelated to AWS LambdabugThis issue is a bug.effort/smallSmall work item – less than a day of effortgood first issueRelated to contributions. See CONTRIBUTING.mdp2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions