Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Fn::ImportValue in Fn::Sub not working for SAM template #372

Closed
nomanyaqubny-zz opened this issue Apr 6, 2018 · 4 comments
Closed

Comments

@nomanyaqubny-zz
Copy link

nomanyaqubny-zz commented Apr 6, 2018

Description:
I am trying to define Serverless API resource. But having trouble in defining location of swagger specification file using function ImportValue.

Steps to reproduce the issue:
I am not able to define AWS::Serverless::Api resource having nested function ImportValue in Location. I have tried following three ways, none of them work.

Note: Stack parameters are defined properly and export value from other stack exists. Not showing them here for brevity reason.

ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
        Name: !Sub ${AWS::StackName}-API
        StageName: !Ref ApiGatewayStageName
        DefinitionBody:
          'Fn::Transform':
            Name: 'AWS::Include'
            Parameters:
              Location:
                Fn::Sub:
                - s3://${BucketName}/${SwaggerSpecificationS3Key}
                - BucketName:
                    Fn::ImportValue:
                      !Sub "${EnvironmentName}-dist-bucket-${AWS::Region}" 
ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
        Name: !Sub ${AWS::StackName}-API
        StageName: !Ref ApiGatewayStageName
        DefinitionBody:
          'Fn::Transform':
            Name: 'AWS::Include'
            Parameters:
              Location:
                Fn::Sub:
                - s3://${BucketName}/${SwaggerSpecificationS3Key}
                - BucketName:
                    !ImportValue 'dev-dist-bucket-us-east-1' 
ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
        Name: !Sub ${AWS::StackName}-API
        StageName: !Ref ApiGatewayStageName
        DefinitionBody:
          'Fn::Transform':
            Name: 'AWS::Include'
            Parameters:
              Location:
                Fn::Sub:
                - s3://${BucketName}/${SwaggerSpecificationS3Key}
                - BucketName:
                    Fn::ImportValue: 'dev-dist-bucket-us-east-1' 

Cloudformation shows following error.

FAILED - The value of parameter Location under transform Include must resolve to a string, number, boolean or a list of any of these.

However, if I do not use ImportValue it works with a nested Fn::Sub

ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
        Name: !Sub ${AWS::StackName}-API
        StageName: !Ref ApiGatewayStageName
        DefinitionBody:
          'Fn::Transform':
            Name: 'AWS::Include'
            Parameters:
              Location:
                Fn::Sub:
                - s3://${BucketName}/${SwaggerSpecificationS3Key}
                - BucketName:
                    Fn::Sub: dist-bucket-${EnvironmentName}-${AWS::Region} 

Is it function ImportValue that cannot be used under function Sub?

or

Is it yaml format that does not support ImportValue under a Sub?

@sanathkr
Copy link
Contributor

sanathkr commented Apr 6, 2018

This would be a CloudFormation question because SAM does not explicitly parse any of the ImportValue notations. My guess is that nesting import value might not work. I am not sure

@nomanyaqubny-zz
Copy link
Author

I can create other resource types and output expected value in the output section of my template using nested import value. I even tried using Join function having nested Import value.

@sanathkr
Copy link
Contributor

sanathkr commented Apr 6, 2018

This is probably something specific to the Fn::Include, which is also a transform. Unfortunately we are focused on the SAM Transform here and don't have insights into Fn::Include.

@yvele
Copy link

yvele commented May 2, 2018

I've got the same problem 😞

Isn't that related to #22 and aws/aws-sam-cli#30?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants