question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(lambda): Incorrect profiler arn on import when profiling is off

See original GitHub issue

What is the problem?

When importing an existing profiling group into a lambda function using ProfilingGroup.fromProfilingGroupArn if profiling is flipped to false, the lambda role policy receives an invalid profiling group arn on it’s resource.

The resource arn becomes arn:aws:codeguru-profiler:<region>:<accountid>:profilingGroup/profilingGroup

The name of the profiling group is invalid in this case.

Reproduction Steps

import * as cdk from '@aws-cdk/core';
import * as codeguru from '@aws-cdk/aws-codeguruprofiler';
import * as lambda from '@aws-cdk/aws-lambda';

const app = new cdk.App();
const stack = new cdk.Stack(app, "Test");

const profilingGroup = codeguru.ProfilingGroup.fromProfilingGroupArn(this, "ProfilingGroup", "somearnhere");
const func = new lambda.Function(this, "Function", {
  ... // your lambda props here
  runtime: lambda.Runtime.PYTHON_3_7,
  profilingGroup,
  profiling: false, // Or this key can simply be omitted
});

Using the code above the environment variable for AWS_CODEGURU_PROFILER_GROUP_ARN will result in arn:aws:codeguru-profiler:us-west-2:0123456789:profilingGroup/profilingGroup (account id just for the sake of valid arn pattern)

What did you expect to happen?

Expected result is for profiling to simply be switched off, but the profiling group arn injected into the environment variables should still be the arn of the profiling group being imported in the lambda function definition.

What actually happened?

The environment variable AWS_CODEGURU_PROFILER_GROUP_ARN is set to arn:aws:codeguru-profiler:us-west-2:0123456789:profilingGroup/profilingGroup

CDK CLI Version

2.4.0 (build 993f14d)

Framework Version

No response

Node.js Version

v14.18.2

OS

Ubuntu

Language

Typescript

Language Version

~4.5.4

Other information

The issue is caused by this line https://github.com/aws/aws-cdk/blob/ddc2bc6ae64fe14ddb4a03122c90dfcf954f149f/packages/%40aws-cdk/aws-lambda/lib/function.ts#L647

If a profiling group is being imported, the correct values should be injected, and the correct iam permissions should be given regardless of whether or not profiling is enabled. Instead the value of AWS_CODEGURU_PROFILER_ENABLED should be set depending on the props passed to the lambda.Function constructor.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
shadogarcommented, Jan 10, 2022

I would be happy to open a PR to fix this bug, if that is alright with the cdk team

0reactions
github-actions[bot]commented, Oct 18, 2022

⚠️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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

All Java Runtimes - Amazon CodeGuru Profiler
Wrap your AWS Lambda function's logic inside a utility from the CodeGuru Profiler profiling agent. package example; import com.amazonaws.
Read more >
aws.lambda.Function - Pulumi
Documentation for the aws.lambda.Function resource with examples, input properties, output properties, lookup functions, and supporting types.
Read more >
CodeGuruProfiler — Boto3 Docs 1.26.33 documentation - AWS
Amazon CodeGuru Profiler provides different visualizations of profiling data to help you identify what code is running on the CPU, see how much...
Read more >
Terraform Import - Leaving Click Ops Behind - Earthly Blog
From Click Ops To GitOpsPreviously I built a REST API, deployed it into a container and got it all running on AWS as...
Read more >
How to choose an AWS profile when using boto3 to connect to ...
I am using the Boto 3 python library, and want to connect to AWS CloudFront. I need to specify the correct AWS Profile...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found