AWS Cloudformation, Output value from Custom Resou

2019-08-25 02:37发布

问题:

I wanted to output a value I get form an Cloudformation Custom Resource. I'm definitely returning the value, but I wasn't sure how to reference it in an Output

This is my template.yml:

Outputs:
  customresourceoutput:
    Value:
      !GetAtt creates3bucketlambda.myvalue

Resources:
  creates3bucketlambda:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs6.10
      CodeUri: setups3bucket
      MemorySize: 512
      Timeout: 300
      Policies:
        - AWSLambdaBasicExecutionRole
        - AmazonS3FullAccess

  Creates3BucketLoginPage:
    Type: Custom::AppConfiguration
    Properties:
      ServiceToken: !GetAtt creates3bucketlambda.Arn
      aOrg:
        !Ref aOrg

The Error I get is:

Failed to create the changeset: Waiter 
ChangeSetCreateComplete failed: Waiter encountered a terminal failure 
state Status: FAILED. Reason: Template error: resource 
creates3bucketlambda does not support attribute type myvalue in 
Fn::GetAtt

I'm not sure if I use a !Sub, !Ref,

回答1:

So basically you can return two things from the AWS::Serverless::Function

  customresourceoutput:
    Value:
      !GetAtt creates3bucketlambda.Arn -> arn of lambda function

and

  customresourceoutput:
    Value:
      !Ref creates3bucketlambda -> name of lambda function

More details about serverless function outputs here.

If you're interested in AWS::CloudFormation::CustomResource there is also a documentation for that.

You can use Fn::GetAtt like:

  customresourceoutput:
    Value:
      !GetAtt customerResource.responseKeyName -> name of the key from the response