7

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 because of Fn::Transform or AWS::Include?

Noman Yaqub
  • 71
  • 1
  • 4
  • I've got the same problem.. See also https://github.com/awslabs/serverless-application-model/issues/372 (you created it ^_^) – Yves M. May 02 '18 at 13:17
  • Any news on this? The github issue referenced is closed... – Ludo Sep 23 '18 at 11:26
  • Any particular reason why your first examples reference `dev-dist-bucket-us-east-1` (environment first) and the example that works is `dist-bucket-${EnvironmentName}-${AWS::Region}` (environment after)? – tyron Oct 25 '18 at 19:45
  • @tyron it just happened to be the way my stack output variable and distribution bucket name is defined. Example that works is because of the fact, I have no `Fn::Import` under `Fn::Sub` or vice versa. – Noman Yaqub Oct 29 '18 at 18:00
  • @Ludo no news mate. SAM guys closed it by saying it is not specific to them but cloudformation/Include fn. – Noman Yaqub Oct 29 '18 at 18:04
  • @NomanYaqub I was just trying to understand if you have both `dev-dist-bucket-us-east-1` and `dist-bucket-dev-us-east-1` buckets created. – tyron Nov 18 '18 at 13:34

0 Answers0