【发布时间】:2022-01-13 05:43:33
【问题描述】:
我目前正在尝试为我的 AWS lambda 函数启用预置并发。我已经想到我只能在 Lambda 函数版本或 Lambda 函数别名上执行此操作。但是我很难将我的 API Gateway 指向这个版本,它似乎总是指向基本功能,而不是版本。
在 UI 中,我可以轻松地将我的 Lambda 函数版本附加到 API 网关端点,但我不知道如何在我的 SAM 模板中执行此操作。
这是我目前拥有的:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "Desc.",
"Parameters": { },
"Resources": {
"MyLambdaFunction": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Runtime": "dotnetcore3.1",
"CodeUri": "MyCodeUri",
"MemorySize": 1024,
"Timeout": 30,
"Events": {
"HttpEvent1": {
"Type": "Api",
"Properties": {
"Path": "/v1/test",
"Method": "GET",
"RestApiId": {
"Ref": "ApiGateway"
}
}
}
},
"Handler": "MyNamespace::MyNamespace.MyFunc::RunAsync"
}
},
"MyLambdaFunctionConcurrentV1": {
"Type": "AWS::Lambda::Version",
"Properties": {
"FunctionName": {
"Ref": "MyLambdaFunction"
},
"ProvisionedConcurrencyConfig": {
"ProvisionedConcurrentExecutions": 1
}
}
},
"ApiGateway": {
"Type": "AWS::Serverless::Api",
"Properties": {
"StageName": {
"Ref": "ApiStageName"
},
"Cors": {
"AllowCredentials": true,
"AllowHeaders": "'*'",
"AllowMethods": "'*'",
"AllowOrigin": "'*'",
"MaxAge": "'600'"
}
}
}
},
"Outputs": {
"ApiUrl": {
"Description": "API Gateway Endpoint URL",
"Value": {
"Fn::Sub": "https://${ApiGateway}.execute-api.${AWS::Region}.${AWS::URLSuffix}/${ApiStageName}"
},
"Export": {
"Name": {
"Fn::Sub": "${AWS::StackName}-ApiUrl"
}
}
}
}
}
所以我可以部署我的 Lambda 函数、我的 API 网关和我的版本。但我不知道如何将 API 网关链接到我的版本。
【问题讨论】:
标签: amazon-web-services aws-lambda amazon-cloudformation aws-api-gateway aws-sam