Fn :: ImportValue没有扩展

时间:2017-09-17 13:01:21

标签: amazon-web-services amazon-cloudformation aws-codepipeline aws-codebuild

我有一个SAM模板,用于创建导出API端点的API网关API:

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: 'API Server for Skynet: AWS Management Assistant'
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      DefinitionUri: swagger.yml
      StageName: prod
      Variables:
        Region: !Ref AWS::Region
        AccountId: !Ref AWS::AccountId

Outputs:
  ApiEndpoint:
    Description: API Endpoint
    Value: !Sub
      - 'https://${ApiId}.execute-api.${AWS::Region}.amazonaws.com/prod'
      - {ApiId: !Ref ApiGatewayApi}
    Export:
      Name: !Sub '${AWS::StackName}-ApiEndpoint'

在我的CodePipeline / CodeBuild堆栈中:我引用它:

CodeBuildWeb:
    Type: AWS::CodeBuild::Project
    Properties:
      Name: !Sub '${PipelineName}-web'
      Artifacts:
        Type: CODEPIPELINE
      Environment:
        ComputeType: BUILD_GENERAL1_SMALL
        Image: aws/codebuild/nodejs:7.0.0
        Type: LINUX_CONTAINER
        EnvironmentVariables:
          - Name: S3_BUCKET
            Value: !Ref S3WebBucket
          - Name: API_URL
            Value: Fn::ImportValue
              !Sub '${PipelineName}-server-ApiEndpoint'
      ServiceRole: !Ref CodeBuildRole
      Source:
        BuildSpec: 'web/buildspec.yml'
        Type: CODEPIPELINE

问题是,它没有扩展,在我的代码中,我认为ApiEndpoint为Fn::ImportValue !Sub '${PipelineName}-server-ApiEndpoint'这里有什么问题?

1 个答案:

答案 0 :(得分:1)

好的,我发现了我的错误:

- Name: API_URL
    Value: Fn::ImportValue:
        !Sub '${PipelineName}-server-ApiEndpoint'

我应该在:

之后添加Fn::ImportValue