简体   繁体   English

如何在 cloudformation lambda 中为 aws lambda 设置最大重试次数?

[英]How can i set the maximumRetryAttempt for aws lambda in the cloudformation lambda?

I have a serverless project created throught visual studio and i'm looking for setting the maximumRetryAttempt of a specific lambda in the cloudformation template.我有一个通过 Visual Studio 创建的无服务器项目,我正在寻找在 cloudformation 模板中设置特定 lambda 的最大重试次数。 I saw EventInvokeConfig, however the lambda function name is generated automatically and different from each environment.我看到了 EventInvokeConfig,但是 lambda function 名称是自动生成的,并且每个环境都不同。 I am wondering if there is an aws specific parameter to get a lambda function name?我想知道是否有特定于 aws 的参数来获取 lambda function 名称?

  "EventInvokeConfig": {
  "Type" : "AWS::Lambda::EventInvokeConfig",
  "Properties" : {
      "FunctionName" : "???",
      "MaximumRetryAttempts" : 0,
      "Qualifier" : "$LATEST"
    }
}

Here is my serverless template这是我的无服务器模板

{
 "AWSTemplateFormatVersion":"2010-09-09",
 "Transform":"AWS::Serverless-2016-10-31",
 "Description":"An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
 "Resources":{
    "MyFunctionLambda":{
       "Type":"AWS::Serverless::Function",
       "Properties":{
          "Handler":"MyPlatformServerless::MyPlatformServerless.Lambdas.MyFunctionLambda::FunctionHandler",
          "Runtime":"dotnetcore2.1",
          "CodeUri":"",
          "Description":"Default function",
          "MemorySize":512,
          "Timeout":60,
          "Role":null
       }
    }
 }
}

You can make use of the Ref instrinsic function.您可以使用Ref内在 function。 For the resource of type AWS::Serverless::Function the returned value is the name of the function.对于AWS::Serverless::Function类型的资源,返回值为 function 的名称。

This can be referenced in other resources defined in the template.这可以在模板中定义的其他资源中引用。 For EventInvokeConfig , the template would look like对于EventInvokeConfig ,模板看起来像

{
    "AWSTemplateFormatVersion":"2010-09-09",
    "Transform":"AWS::Serverless-2016-10-31",
    "Description":"An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
    "Resources":{
        "MyFunctionLambda":{
            "Type":"AWS::Serverless::Function",
            "Properties":{
                "Handler":"MyPlatformServerless::MyPlatformServerless.Lambdas.MyFunctionLambda::FunctionHandler",
                "Runtime":"dotnetcore2.1",
                "CodeUri":"",
                "Description":"Default function",
                "MemorySize":512,
                "Timeout":60,
                "Role":null
            }
        },
        "EventInvokeConfig": {
            "Type" : "AWS::Lambda::EventInvokeConfig",
            "Properties" : {
                "FunctionName" : { "Ref" : MyFunctionLambda },
                "MaximumRetryAttempts" : 0,
                "Qualifier" : "$LATEST"
            }
        }
    }
}

Your issue might have resolved already but you can improve the code.您的问题可能已经解决,但您可以改进代码。 As you're using Serverless (SAM) you can directly specify the EventInvokeConfig in the lambda resource properties and no need of another resource creation.当您使用无服务器 (SAM) 时,您可以直接在 lambda 资源属性中指定EventInvokeConfig ,而无需创建其他资源。 Please find the below snippet:请找到以下代码段:

{
    "AWSTemplateFormatVersion":"2010-09-09",
    "Transform":"AWS::Serverless-2016-10-31",
    "Description":"An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
    "Resources":{
        "MyFunctionLambda":{
            "Type":"AWS::Serverless::Function",
            "Properties":{
                "Handler":"MyPlatformServerless::MyPlatformServerless.Lambdas.MyFunctionLambda::FunctionHandler",
                "Runtime":"dotnetcore2.1",
                "CodeUri":"",
                "Description":"Default function",
                "MemorySize":512,
                "Timeout":60,
                "Role":null,
                "EventInvokeConfig": {
                    "MaximumRetryAttempts" : 0
                }
            }
        }
    }
}

You can also specify other attributes like DestinationConfig and MaximumEventAgeInSeconds in the EventInvokeConfig object.您还可以在EventInvokeConfig object 中指定其他属性,例如DestinationConfigMaximumEventAgeInSeconds

References: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-eventinvokeconfiguration.html参考: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-eventinvokeconfiguration.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 AWS Lambda 中加载 AWS Cloudformation 的 Output? - How Can I Load The Output of AWS Cloudformation In AWS Lambda? 如何仅在创建 AWS::Cloudformation::Stack 时调用 AWS::Lambda::Function? - How can I invoke an AWS::Lambda::Function only on the creation of a AWS::Cloudformation::Stack? 如何在CloudFormation中将目标设置为Lambda以进行AWS Kinesis数据分析 - How to set destination as lambda in cloudformation for aws kinesis data analytics 我可以使用 CloudFormation 模板更新 AWS Lambda function 吗? - Can I update AWS Lambda function using CloudFormation template? 如何使用 CloudFormation 模板更新 AWS Lambda function - How do I update AWS Lambda function using CloudFormation template 如何在 VPC 内连接 AWS lambda 以连接到 cloudformation 堆栈? - How can I connect an AWS lambda inside a VPC to connect to a cloudformation stack? AWS CloudFormation中的Lambda函数 - Lambda Function in AWS CloudFormation 如何使用aws中的cloudformation在api网关中请求参数并将其传递给lambda函数? - How can I request parameters in api gateway using cloudformation in aws and pass it down to lambda function? AWS lambda:如何在 lambda 中运行 aws cli 命令 - AWS lambda: how can I run aws cli commands in lambda 如何将 AWS Lambda 转换回 CloudFormation 模板 - How to convert AWS Lambda back into CloudFormation template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM