簡體   English   中英

如何在 cloudformation lambda 中為 aws lambda 設置最大重試次數?

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

我有一個通過 Visual Studio 創建的無服務器項目,我正在尋找在 cloudformation 模板中設置特定 lambda 的最大重試次數。 我看到了 EventInvokeConfig,但是 lambda function 名稱是自動生成的,並且每個環境都不同。 我想知道是否有特定於 aws 的參數來獲取 lambda function 名稱?

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

這是我的無服務器模板

{
 "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
       }
    }
 }
}

您可以使用Ref內在 function。 對於AWS::Serverless::Function類型的資源,返回值為 function 的名稱。

這可以在模板中定義的其他資源中引用。 對於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"
            }
        }
    }
}

您的問題可能已經解決,但您可以改進代碼。 當您使用無服務器 (SAM) 時,您可以直接在 lambda 資源屬性中指定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": {
                    "MaximumRetryAttempts" : 0
                }
            }
        }
    }
}

您還可以在EventInvokeConfig object 中指定其他屬性,例如DestinationConfigMaximumEventAgeInSeconds

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM