简体   繁体   English

如何确定 AWS Lambda 是使用 AWS CDK 创建的?

[英]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.

相关问题 我可以在使用 aws_cdk 创建 lambda 后立即调用它吗? - Can I invoke a lambda right after it's created using aws_cdk? 如何使用 aws cdk (JAVA) 每 15 分钟创建一个 cloudwatch 规则来触发 lambda function? - How can i create a cloudwatch rule to trigger a lambda function every 15 minutes using aws cdk (JAVA)? 如何使用 AWS CDK 中的 InvokeLambda 将 JSON 传递给 AWS StepFunction 中的 lambda - How do I pass JSON to lambda in AWS StepFunction using InvokeLambda in AWS CDK AWS CDK 将路径应用到已创建的 lambda 角色 - AWS CDK apply path to lambda role created "如何使用 CDK 生成 AWS SES SMTP 凭证?" - How can I generate AWS SES SMTP credentials using the CDK? 如何使用 AWS CLI 创建 AWS Lambda 函数? - How can I create an AWS Lambda function using the AWS CLI? AWS CDK 应用程序如何“引用”已经创建的 aws lambda function(不在堆栈中创建新的)? - AWS CDK application how to “reference” already created aws lambda function (without creating a new one in a stack)? 如何从 AWS CDK 编辑 AWS EKS 中的节点组 - How can I edit Nodegroup in AWS EKS from AWS CDK 如何使用 AWS CDK 将现有 Lambda 函数的别名指定为 DynamoDB 触发器? - How do I specify an existing Lambda function's alias as a DynamoDB trigger using the AWS CDK? 使用 AWS CDK 配置 Lambda 加热器 - Configure a Lambda Warmer using AWS CDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM