AWS CloudFormation中Fn::GetAtt函数用于获取资源的属性值。如果在使用Fn::GetAtt时出现模板错误,可能是以下几种原因:
Fn::GetAtt: [logicalNameOfResource, attributeName]
。确保逗号和方括号使用正确。示例代码:
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-bucket
Outputs:
BucketNameOutput:
Value: !Ref MyBucket
Description: The name of the bucket
BucketARNOutput:
Value: !GetAtt MyBucket.Arn
Description: The ARN of the bucket
示例代码:
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-bucket
Outputs:
BucketNameOutput:
Value: !Ref MyBucket
Description: The name of the bucket
BucketARNOutput:
Value: !GetAtt NonExistentResource.Arn
Description: The ARN of the bucket
示例代码:
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-bucket
Outputs:
BucketNameOutput:
Value: !Ref MyBucket
Description: The name of the bucket
BucketARNOutput:
Value: !GetAtt MyBucket.NonExistentAttribute
Description: The ARN of the bucket
通过检查语法、逻辑名称和属性名称,您应该能够解决AWS CloudFormation中Fn::GetAtt的模板错误。