Fn::GetAtt - AWS CloudFormation

Fn::GetAtt

Fn::GetAtt 組み込み関数は、テンプレートのリソースから属性の値を返します。特定のリソースに対する GetAtt の戻り値の詳細については、「リソースとプロパティのリファレンス」でそのリソースのドキュメントを参照してください。

宣言

JSON

{ "Fn::GetAtt" : [ "logicalNameOfResource", "attributeName" ] }

YAML

完全関数名の構文:

Fn::GetAtt: [ logicalNameOfResource, attributeName ]

短縮形の構文:

!GetAtt logicalNameOfResource.attributeName

パラメータ

logicalNameOfResource

必要な属性を含むリソースの論理名 (論理 ID とも呼ばれます)。

attributeName

必要としている値のある、リソース固有の属性の名前です。各リソースタイプで使用できる属性の詳細については、リソースの参照ページに説明されています。

戻り値

属性の値です。

1 つの文字列を返す

このコード例は、論理名 myELB と共に、ロードバランサーの DNS 名を含む文字列を返します。

JSON

"Fn::GetAtt" : [ "myELB" , "DNSName" ]

YAML

!GetAtt myELB.DNSName

複数の文字列を返す

以下のテンプレート例では、SourceSecurityGroup.OwnerAlias という論理名のロードバランサーの SourceSecurityGroup.GroupNamemyELB を返しています。

JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "myELB": { "Type": "AWS::ElasticLoadBalancing::LoadBalancer", "Properties": { "AvailabilityZones": [ "eu-west-1a" ], "Listeners": [ { "LoadBalancerPort": "80", "InstancePort": "80", "Protocol": "HTTP" } ] } }, "myELBIngressGroup": { "Type": "AWS::EC2::SecurityGroup", "Properties": { "GroupDescription": "ELB ingress group", "SecurityGroupIngress": [ { "IpProtocol": "tcp", "FromPort": 80, "ToPort": 80, "SourceSecurityGroupOwnerId": { "Fn::GetAtt": [ "myELB", "SourceSecurityGroup.OwnerAlias" ] }, "SourceSecurityGroupName": { "Fn::GetAtt": [ "myELB", "SourceSecurityGroup.GroupName" ] } } ] } } } }
YAML
AWSTemplateFormatVersion: 2010-09-09 Resources: myELB: Type: AWS::ElasticLoadBalancing::LoadBalancer Properties: AvailabilityZones: - eu-west-1a Listeners: - LoadBalancerPort: '80' InstancePort: '80' Protocol: HTTP myELBIngressGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: ELB ingress group SecurityGroupIngress: - IpProtocol: tcp FromPort: 80 ToPort: 80 SourceSecurityGroupOwnerId: !GetAtt myELB.SourceSecurityGroup.OwnerAlias SourceSecurityGroupName: !GetAtt myELB.SourceSecurityGroup.GroupName

サポートされている関数

Fn::GetAtt 論理リソース名に関数を使用することはできません。リソースの論理 ID である文字列を指定する必要があります。

Fn::GetAtt 属性名には、Ref 関数を使用できます。