amazon-web-services - Fn::ImportValue 未扩展

标签 amazon-web-services aws-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' 这里出了什么问题?

最佳答案

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

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

我应该在Fn::ImportValue之后添加一个:

关于amazon-web-services - Fn::ImportValue 未扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46264375/

相关文章:

python - 在用户数据中将 powershell 脚本发送到 Windows ec2

node.js - 如何使用 Bluebird promise AWS SQS

amazon-web-services - 有没有办法访问AWS CloudFormation中的 "clone"资源

amazon-web-services - 使用 CloudFormation 创建 ECS 集群错误

terraform - Terraform 中的 VPCGatewayAttachment?

amazon-web-services - Amazon EMR、Hue 设置密码不起作用

amazon-web-services - 通过 AWS CloudFormation 创建 Amazon VPC 时出现 "CIDR is invalid"

amazon-web-services - 具有 SAM 的 API 网关未正确更新

aws-cdk - 与现有代码管道一起使用的 AWS CDK 管道

amazon-web-services - 动态更改 AWS CodePipeline 上的分支