简体   繁体   中英

How can I identify that an AWS Lambda was created using the AWS CDK?

I'm looking for a way to identify that a AWS Lambda was provisioned with the AWS CDK. Is there a tag, or some other type of metadata to identify this? SAM provides a tag lambda_createdBy:SAM . I could add a tag myself, but for the case of an organization that has thousands of Lambdas already provisioned identifying this requires changing code for all of them.

AFAIK CDK doesn't add any special CDK specific tag. I believe some resource get auto tagged with the CF template they are a part of though so there's that.

Rather than modify the code across the board you can instead write a CDK Aspect that adds the tag to any lambda functions in the app.

Something like:

class FunctionTagger implements IAspect {
  public visit(node: IConstruct): void {
    if (node instanceof lambda.Function) {
      Tags.add('myTag', 'myValue', node)
    }
  }
}

// Apply to the stack
stack.node.applyAspect(new FunctionTagger());

The Lambda func deployed by CDK will be propagated the tag with key aws:cloudformation:stack-name .

Then you can check if the stack with resource named CDKMetadata . For example,

aws cloudformation describe-stack-resource --stack-name my-stack-name --logical-resource-id CDKMetadata

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM