[英]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.我正在寻找一种方法来识别 AWS Lambda 是使用 AWS CDK 配置的。 Is there a tag, or some other type of metadata to identify this?是否有标签或其他类型的元数据来识别这一点? SAM provides a tag lambda_createdBy:SAM
. SAM 提供了一个标签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.我可以自己添加一个标签,但对于一个已经配置了数千个 Lambda 的组织,识别这需要更改所有这些的代码。
AFAIK CDK doesn't add any special CDK specific tag. AFAIK CDK 不添加任何特殊的 CDK 特定标签。 I believe some resource get auto tagged with the CF template they are a part of though so there's that.我相信某些资源会自动标记为 CF 模板,但它们是其中的一部分,所以就是这样。
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.您可以编写一个CDK 方面,将标签添加到应用程序中的任何 lambda 函数,而不是全面修改代码。
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
. CDK 部署的 Lambda func 将传播具有密钥aws:cloudformation:stack-name
的标签。
Then you can check if the stack with resource named CDKMetadata
.然后您可以检查是否有名为CDKMetadata
资源的堆栈。 For example,例如,
aws cloudformation describe-stack-resource --stack-name my-stack-name --logical-resource-id CDKMetadata
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.