我有一个自定义 CloudFormation 资源,如果它不存在,它会创建一个 S3 存储桶。这是代码:
S3CustomResource:
Type: Custom::S3CustomResource
Properties:
ServiceToken: !GetAtt AWSLambdaFunction.Arn
the_bucket: !Ref S3BucketName
AWSLambdaFunction:
Type: "AWS::Lambda::Function"
Properties:
Description: "Work with S3 Buckets!"
FunctionName: !Sub '${AWS::StackName}-${AWS::Region}-lambda'
Handler: index.handler
Role: !GetAtt AWSLambdaExecutionRole.Arn
Timeout: 360
Runtime: python3.6
Code:
ZipFile: |
import boto3
import cfnresponse
def handler(event, context):
# Init ...
the_event = event['RequestType']
print("The event is: ", str(the_event))
response_data = {}
s_3 = boto3.client('s3')
# Retrieve parameters
the_bucket = event['ResourceProperties']['the_bucket']
try:
if the_event in ('Create', 'Update'):
print("Requested to create S3 bucket: ", str(the_bucket))
for bucket_name in the_bucket:
print("Creating: ", str(bucket_name))
s_3.create_bucket(Bucket=the_bucket)
elif the_event == 'Delete':
print("Whoopsie, this bucket has some seriuos information in it - let's not delete it")
# Everything OK... send the signal back
print("Execution succesfull!")
cfnresponse.send(event,
context,
cfnresponse.SUCCESS,
response_data)
except Exception as e:
print("Execution failed...")
print(str(e))
response_data['Data'] = str(e)
cfnresponse.send(event,
context,
cfnresponse.FAILED,
response_data)
我想在我的其他 CloudFormation 资源中引用此存储桶的 ARN。S3CustomResource 资源仅显示 CloudWatch 日志名称的 PhysicalID。如何让 CloudFormation 在“资源”选项卡中将存储桶 ARN 显示为 PhysicalID?