aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

RequestMappingTemplateS3Location does not work with Fn::If

Open fcobia opened this issue 5 years ago • 3 comments

I have a template for an AppSync Pipeline Function that references a different template depending on a condition. While SAM normally translates the location to the proper s3 location, it does not work if I have an Fn::If.

I would have expected that SAM would translate both locations specified in the Fn::If.

Example:

  EnvironmentPipelineFunc:
    Type: "AWS::AppSync::FunctionConfiguration"
    Condition: IsProd
    Properties:
      Name: "Environment"
      RequestMappingTemplateS3Location: !If [IsProd, "prodRequest.vm", "testRequest.vm"]
      ResponseMappingTemplateS3Location: !If [IsProd, "prodResponse.vm", "testResponse.vm"]
      DataSourceName: !GetAtt "VTLDataSource.Name"
      FunctionVersion: "2018-05-29"
      ApiId: !GetAtt "API.ApiId"

fcobia avatar Apr 18 '19 14:04 fcobia

Hi @fcobia. You're correct that SAM does not currently support Fn::If used with local file paths. This local path support is really a SAM CLI feature so I'll have the issue transferred to the SAM CLI GitHub repo.

As a side note, in your example, you have Condition: IsProd on your entire EnvironmentPipelineFunc resource so it doesn't seem to make sense to have the Fn::If within that resource use IsProd as the condition since if that's false, the entire resource won't exist in the deployment.

jlhood avatar Apr 19 '19 18:04 jlhood

Sorry about the condition. That was actually part of my fix and I left it in. What I ended up doing was creating two resources with a condition so that only the correct one is created, but that also means everywhere I reference the resource, I have to put an Fn::If to make sure I reference the correct resource. So I have a lot of Ifs instead of a single one.

fcobia avatar Apr 19 '19 19:04 fcobia

Ok makes sense. Just wanted to point it out in case you weren't aware! 😊

jlhood avatar Apr 19 '19 19:04 jlhood