- Newest
- Most votes
- Most comments
The issue here was Read failing due to CloudFormation behaving differently than the Contract Tests. The Contract Tests do not follow the CloudFormation model rules, they are more permissive.
You can pass the output values from the custom resource in the response data being returned as a parameter to the custom resource response objects
Replicating the scenario at my end, I tried to create a sample lambda backed custom resource responsible for creation of a new EC2 instance and then returned the value of the ‘InstanceId' as a return value.
Resources:
LambdaFunction:
Type: 'AWS::Lambda::Function'
Properties:
FunctionName: executeFn
Timeout: 900
Code:
ZipFile: |
import boto3, json
import cfnresponse
def handler(event, context):
ec2 = boto3.client('ec2')
print ("Createing new instance:")
instance = ec2.run_instances(
ImageId='ami-061e2417489356de3',
InstanceType='t2.micro',
MaxCount=1,
MinCount=1
)
instance_id = instance['Instances'][0]['InstanceId']
responseValue = instance_id
responseData = {}
responseData['Data'] = responseValue
cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData)
Handler: index.handler
Role: 'arn:aws:iam::xxxxxxxxxxxx:role/testLambda'
Runtime: python3.7
CustomResource:
Type: 'AWS::CloudFormation::CustomResource'
DependsOn: LambdaFunction
Version: '1.0'
Properties:
ServiceToken: !GetAtt LambdaFunction.Arn
Description: Custom resource to invoke lambda
Outputs:
InstanceId:
Value: !GetAtt CustomResource.Data
Now, here in this example, you can refer that lambda function associated with the custom resource returns the instance id as a value in the Data which is then displayed as an output to the stack created using the GetAtt intrinsic function.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-responses.html
Relevant content
- asked 7 months ago
- asked 3 years ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 14 days ago
Thanks for the response.
The question isn't how to return Outputs from a custom resource, it's why aren't the Outputs showing up in CF even though SAM and
test-type
indicate that they are.Is there a way to dump the response object CF is receiving from the custom resource?
Thanks again for the response.