参数名称的AWS Cloudformation嵌套堆栈参数类型不存在

时间:2018-09-27 16:55:16

标签: amazon-web-services amazon-cloudformation

我正在尝试使用cloudformation将父堆栈和嵌套堆栈部署到AWS。父堆栈看起来像这样

AWSTemplateFormatVersion: '2010-09-09'

Parameters:
  VPC:
    Description: Choose which VPC the Lambda-functions should be deployed to
    Type: AWS::EC2::VPC::Id
    Default: vpc-sdjkfnsdjklfn

  Subnets:
    Description: Choose which subnets Lambda-functions should be deployed to
    Type: CommaDelimitedList
    Default: "subnet-sdoifno, subnet-sdofjnsdo"

  SecurityGroup:
    Description: Select the Security Group to use for the Lambda-functions
    Type: AWS::EC2::SecurityGroup::Id
    Default: sg-sdklfnsdkl

  Role:
    Description: Role for Lambda functions
    Type: String
    Default: arn:aws:iam::dlfksd:role/ssdfnsdo

Resources:
  RestApi:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: "my-api"
        Description: "SPP Lambda API"

  Stack1:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: 'https://s3.amazonaws.com/bucket/template1.yml'
      Parameters:
        VPC: !Ref VPC
        Subnets: !Join
                   - ','
                   - !Ref Subnets
        SecurityGroup: !Ref SecurityGroup
        Role: !Ref Role
        RestApi: !Ref RestApi
        ApiResourceParent: !GetAtt "RestApi.RootResourceId"

子堆栈看起来像这样

AWSTemplateFormatVersion: '2010-09-09'

Parameters:
  VPC:
    Type: AWS::EC2::VPC::Id

  Subnets:
    Type: CommaDelimitedList

  SecurityGroup:
    Type: AWS::EC2::SecurityGroup::Id

  Role:
    Type: String

  RestApi:
    Type: AWS::ApiGateway::RestApi

  ApiResourceParent:
     Type: AWS::ApiGateway::Resource

Resources:

    Fucntion:
        Type: AWS::Lambda::Function
        Properties:
          Code:
            S3Bucket: bucket
            S3Key: node_lambdas.zip
          Handler: Function.handler
          Role: !Ref Role
          Runtime: nodejs6.10
          Timeout: 300
          VpcConfig:
            SecurityGroupIds:
              - !Ref SecurityGroup
            SubnetIds: !Ref Subnets
          #Policies: AWSLambdaDynamoDBExecutionRole

    Permission:
        Type: AWS::Lambda::Permission
        Properties:
          Action: lambda:InvokeFunction
          FunctionName: !GetAtt "Function.Arn"
          Principal: "apigateway.amazonaws.com"
          SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/*/*"
    Resource:
         Type: AWS::ApiGateway::Resource
         Properties:
           RestApiId: !Ref RestApi
           ParentId: !Ref ApiResourceParent
           PathPart: addadjustments

运行aws cloudformation deploy --template-file parent-stack.yml --stack-name spp-lambda --region us-east-1 --capabilities CAPABILITY_IAM时出现以下错误

  

嵌入式堆栈   arn:aws:cloudformation:us-east-1:771653148224:stack / spp-lambda-Stack1-97M9BLBUM3A5 / 4a454a50-c274-11e8-b49c-500c28903236   未成功创建:参数验证失败:参数   参数名称RestApi的类型为AWS :: ApiGateway :: RestApi不会   存在,参数名称的参数类型为AWS :: ApiGateway :: Resource   ApiResourceParent不存在

它不会抱怨在父模板中显式定义的参数。我想动态创建和传递它抱怨的参数,因为我事先不知道这些值。我在做什么错了?

1 个答案:

答案 0 :(得分:4)

尽管将某些AWS资源类型支持为cloudformation参数类型,但这并不意味着支持所有资源类型。

您正尝试将API网关值作为AWS特定的参数类型引用,但不受支持:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html#aws-specific-parameter-types

我相信使用String作为类型就足够了。