2

我使用自定义资源运行 CFN 模板来导出 route53 私有托管区域名称。我能够根据需要导出托管区域名称,但无法将此托管区域名称导入另一个堆栈。我收到此错误:

Value of property HostedZoneName must be of type String

任何帮助表示赞赏。谢谢你。这是我的代码。

AWSTemplateFormatVersion: 2010-09-09
Description: CloudFormation exports


Resources:
  LambdaExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
        - Effect: Allow
          Principal:
            Service:
            - lambda.amazonaws.com
          Action:
          - sts:AssumeRole
      Path: "/"
      Policies:
      - PolicyName: root
        PolicyDocument:
          Version: '2012-10-17'
          Statement:
          - Effect: Allow
            Action:
            - "logs:CreateLogGroup"
            - "logs:CreateLogStream"
            - "logs:PutLogEvents"
            - "route53:Get*"
            - "route53:List*"
            - "route53:TestDNSAnswer"
            Resource: "*"
  GetCertARN: 
    Type: "AWS::Lambda::Function"
    DeletionPolicy: Delete
    DependsOn:
      - LambdaExecutionRole
    Properties: 
      Handler: "index.handler"
      Role: 
        Fn::GetAtt: 
          - "LambdaExecutionRole"
          - "Arn"
      Runtime: "python3.7"
      MemorySize: 128
      Timeout: 100
      Code: 
        ZipFile: |
          import boto3
          import botocore
          import cfnresponse
          route53 = boto3.client('route53')
          def handler(event, context):
            hostedZoneName=''
            response2 = route53.list_hosted_zones()
            f=response2['HostedZones']
            for zone in f:
                config=zone["Config"]
                name=zone["Name"]
                e=config["PrivateZone"]
                if ('abcxyz.cloud' in name) and e:
                    hostedZoneName=name
            responseData = {}
            responseData['hostedzonename'] = hostedZoneName
            cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData)
  CertArnInvocation:
    Type: Custom::CertArn
    Properties:
      ServiceToken: !GetAtt GetCertARN.Arn
      Region: !Ref "AWS::Region"

Outputs:
  ExportsStackName:
    Value: !Ref 'AWS::StackName'
    Export:
      Name: !Sub '${AWS::StackName}'

  HostedZoneNameOutput: 
    Value: !GetAtt CertArnInvocation.hostedzonename
    Description: Return Value of private hosted zone name
    Export: 
      Name: !Sub 'nonProdHostedZoneName'
4

1 回答 1

1

您正在HostedZoneNameOutput以以下名称出口nonProdHostedZoneName

    Export: 
      Name: !Sub 'nonProdHostedZoneName'

但它接缝您正在导入(未显示)名为HostedZoneName.

根据评论更新(HostedZoneName是列表,而不是字符串)。修正版:

HostedZoneName: !ImportValue nonProdHostedZoneName
于 2020-07-13T22:46:10.773 回答