首页 > 解决方案 > 模板获取 AWS::EC2::EIP(弹性 IP)的 AllocationID 时出现 AWS CloudFormation 错误

问题描述

我已经创建了一个包含 EIP 资源的堆栈,我正在尝试获取分配 ID,而 CloudFormation 验证器一直对我大喊大叫。我将 EIP 提取到一个非常简单的堆栈中,它是唯一的资源,但我仍然无法获得有效的模板。我是疯了还是 AWS 惹我了??下面是验证失败的简单堆栈模板,如果我将它用作嵌套堆栈,它会在创建时失败。

AWSTemplateFormatVersion: 2010-09-09
Description: Create an EIP to be used by Alliance web proxy EC2 instance.
Resources:
  EIPForProxy:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
Outputs:
  EIPAllocationID:
    Value: !GetAtt EIPForProxy.AllocationID
  EIPPublicIP:
    Value: !Ref EIPForProxy

标签: amazon-web-servicesamazon-ec2amazon-cloudformationelastic-ip

解决方案


作为 VPC 弹性 IP 地址,您只能将其导出为值并将此模板用作父堆栈的子堆栈。您不能使用 GetAtt 函数将其作为值输出。

---
AWSTemplateFormatVersion: '2010-09-09'
Description: Create an EIP to be used by Alliance web proxy EC2 instance.
Resources:
  EIPForProxy:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
Outputs:
  EIPAllocationID:
    Value: 'null'
    Export:
      Name: MyEIP::AllocationId
  EIPPublicIP:
    Value:
      Ref: EIPForProxy


推荐阅读