我如何构建这个JSON CloudFormation模板



从本文中,它展示了如何将AWS::Serverless::Function部署为'代理'来执行路由,a/b测试等。

示例模板是YAML格式的,但我们需要使用JSON,因为AWS dotnet模板是基于JSON构建的。

在YAML中有一行我不知道如何翻译成JSON模板:

LambdaFunctionARN: !Ref LambdaEdgeFunctionSample.Version

在JSON模板中,Ref只是指另一个资源或参数。不能将Ref转换为Resource.Property。您可以使用Fn::GetAtt

我已经尝试了Fn::GetAtt,但错误与"版本是此资源的未知属性";(在编辑器中)和部署期间的Template error: every Fn::GetAtt object requires two non-empty parameters, the resource name and the resource attribute:

"LambdaFunctionARN":{"Fn::GetAtt":["LambdaEdgeFunctionSample","Version"]}}

请注意,这些都是使用AWS::Serverless::下面的功能,所以有更多的转换。

具体来说,当JSON模板被转换时,它会创建:

"LambdaEdgeFunctionSampleVersion1cfc342538": {
"Type": "AWS::Lambda::Version",
"DeletionPolicy": "Retain",
"Properties": {
"FunctionName": {
"Ref": "LambdaEdgeFunctionSample"
}
}
},

但是我不能使用LambdaEdgeFunctionSampleVersion1cfc342538,因为这显然是一个瞬态id。

如何在JSON模板中实现与YAML模板相同的功能?

显然,AWS SAM在实际处理模板之前对!Ref LambdaEdgeFunctionSample.Version进行了转换。

在Json中也是一样SAM会进行转换

{"Ref":"LambdaEdgeFunctionSample.Version"}

转换

{
"Ref": "LambdaEdgeFunctionSampleVersionf76b18e3ba"
}

最新更新