How Do I Structure This JSON CloudFormation Template

Viewed 29

From this article, it shows how to deploy a AWS::Serverless::Function as a 'proxy' to do routing, a/b testing, etc.

The example template is in YAML, but we need to use JSON as that is what the AWS dotnet templates are built on.

There is a line in the YAML that I cannot figure out how to translate to a JSON template:

LambdaFunctionARN: !Ref LambdaEdgeFunctionSample.Version

In a JSON template a Ref just refers to another resource or parameter. You cannot Ref to a Resource.Property. For that you use Fn::GetAtt.

I have tried Fn::GetAtt, but that errors with "Version is an unknown attribute for this resource" (in the editor) and Template error: every Fn::GetAtt object requires two non-empty parameters, the resource name and the resource attribute during deployment:

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

Mind you, these are both using AWS::Serverless::Function underneath, so there's more transforming going on.

Specifically, when the JSON template is transformed, it does create:

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

But I cannot use LambdaEdgeFunctionSampleVersion1cfc342538 as clearly that is a transient id.

How can I accomplish the same as the YAML template in a JSON template?

1 Answers

Apparently, AWS SAM does a transformation on !Ref LambdaEdgeFunctionSample.Version before the template is actually processed.

So, in Json, it's the same and SAM does the transformation:

{"Ref":"LambdaEdgeFunctionSample.Version"}

transforms to

{
  "Ref": "LambdaEdgeFunctionSampleVersionf76b18e3ba"
}
Related