如何从 CloudFormation AWS::Lambda::Alias 中获取函数名称和别名?
How to get just the function name and alias from CloudFormation AWS::Lambda::Alias?
我需要为 API 网关阶段设置一个阶段变量。这个阶段变量必须只是 lambda 函数和别名 (Foo:dev)。它不能是完整的 ARN。然后在 swagger 中使用该变量将 API 网关与具有特定别名的 lambda 函数集成。
看来我唯一能从 AWS::Lambda::Alias 资源中得到的就是 ARN。我如何才能获得名称和别名?
这是舞台资源。 "lamdaAlias" 设置为别名的完整 ARN。
"ApiGatewayStageDev": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"StageName": "dev",
"Description": "Dev Stage",
"RestApiId": {
"Ref": "ApiGatewayApi"
},
"DeploymentId": {
"Ref": "ApiGatewayDeployment"
},
"Variables": {
"lambdaAlias": {
"Ref": "LambdaAliasDev"
}
}
}
}
只需重用用于指定 AWS::Lambda::Alias
资源中的 FunctionName
和 Name
属性的相同值。例如,假设您的资源在您的模板中是这样指定的:
"LambdaAliasDev" : {
"Type" : "AWS::Lambda::Alias",
"Properties" : {
"FunctionName" : { "Ref" : "MyFunction" },
"FunctionVersion" : { "Fn::GetAtt" : [ "TestingNewFeature", "Version" ] },
"Name" : { "Ref" : "MyFunctionAlias" }
}
}
您可以使用 Fn::Join
内部函数将函数和别名组合成一个字符串,如下所示:
"ApiGatewayStageDev": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"StageName": "dev",
"Description": "Dev Stage",
"RestApiId": {
"Ref": "ApiGatewayApi"
},
"DeploymentId": {
"Ref": "ApiGatewayDeployment"
},
"Variables": {
"lambdaAlias": {
"Fn::Join": {[ ":", [
{ "Ref": "MyFunction" },
{ "Ref": "MyFunctionAlias" }
]}
}
}
}
}
假设 MyFunction
是 Foo
并且 MyFunctionAlias
是 dev
,这将根据需要将 lambdaAlias
设置为 Foo:dev
。
我需要为 API 网关阶段设置一个阶段变量。这个阶段变量必须只是 lambda 函数和别名 (Foo:dev)。它不能是完整的 ARN。然后在 swagger 中使用该变量将 API 网关与具有特定别名的 lambda 函数集成。
看来我唯一能从 AWS::Lambda::Alias 资源中得到的就是 ARN。我如何才能获得名称和别名?
这是舞台资源。 "lamdaAlias" 设置为别名的完整 ARN。
"ApiGatewayStageDev": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"StageName": "dev",
"Description": "Dev Stage",
"RestApiId": {
"Ref": "ApiGatewayApi"
},
"DeploymentId": {
"Ref": "ApiGatewayDeployment"
},
"Variables": {
"lambdaAlias": {
"Ref": "LambdaAliasDev"
}
}
}
}
只需重用用于指定 AWS::Lambda::Alias
资源中的 FunctionName
和 Name
属性的相同值。例如,假设您的资源在您的模板中是这样指定的:
"LambdaAliasDev" : {
"Type" : "AWS::Lambda::Alias",
"Properties" : {
"FunctionName" : { "Ref" : "MyFunction" },
"FunctionVersion" : { "Fn::GetAtt" : [ "TestingNewFeature", "Version" ] },
"Name" : { "Ref" : "MyFunctionAlias" }
}
}
您可以使用 Fn::Join
内部函数将函数和别名组合成一个字符串,如下所示:
"ApiGatewayStageDev": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"StageName": "dev",
"Description": "Dev Stage",
"RestApiId": {
"Ref": "ApiGatewayApi"
},
"DeploymentId": {
"Ref": "ApiGatewayDeployment"
},
"Variables": {
"lambdaAlias": {
"Fn::Join": {[ ":", [
{ "Ref": "MyFunction" },
{ "Ref": "MyFunctionAlias" }
]}
}
}
}
}
假设 MyFunction
是 Foo
并且 MyFunctionAlias
是 dev
,这将根据需要将 lambdaAlias
设置为 Foo:dev
。