aws-cloudformation / aws-cloudformation/custom-resource-helper
crhelper appears tp break
- Dominant language
- Python
- Stars
- 383
- Forks
- 61
- PR merge metrics
- No merged PRs in 30d
Description
I've had issues when using crhelper to get it return attributes back to the stack.
This very simple lambda works.
```
def on_event(event, context):
props = event["ResourceProperties"]
print("create new resource with props %s" % props)
message = event['ResourceProperties']['RERUN']
product_id = sc.search_products_as_admin(
Filters={
'FullTextSearch': ['AWS Control Tower Account Factory']
},
)['ProductViewDetails'][0]['ProductViewSummary']['ProductId']
artifact_id = sc.describe_product_as_admin(
Id = product_id
)['ProvisioningArtifactSummaries'][0]['Id']
attributes = {
'ProductId': product_id,
'ArtifactId': artifact_id
}
return { 'Data': attributes }
```
if i replace it with this;
```
import crhelper
import boto3
helper = crhelper.CfnResource()
@helper.create
@helper.update
def get_account_factory_id(event, _):
sc = boto3.client('servicecatalog')
product_id = sc.search_products_as_admin(
Filters={
'FullTextSearch': ['AWS Control Tower Account Factory']
},
)['ProductViewDetails'][0]['ProductViewSummary']['ProductId']
helper.Data['ProductId'] = product_id
artifact_id = sc.describe_product_as_admin(
Id = product_id
)['ProvisioningArtifactSummaries'][0]['Id']
helper.Data['ArtifactId'] = artifact_id
@helper.delete
def no_op(_, __):
pass
def on_event( event, context ):
helper(event, context)
```
I end up with this error.
```
The stack named AccountfactoryStack failed to deploy: CREATE_FAILED (CustomResource attribute error: Vendor response doesn't contain ArtifactId key in object arn:aws:cloudformation:ap-southeast-2:4xxxxxxxx7:stack/AccountfactoryStack/71875c50-f5a8-11ec-ac83-06c5a6d5f3f0|accountTahiprovisioningArtifactIdD6FC5169|5c9f7268-d6e5-45f5-b2fb-8cafdb68e1ee in S3 bucket cloudformation-custom-resource-storage-apsoutheast2)
```
It appears that somethign might be broken here. I love the idea of crhelper, its great, but not being able to use attributes is a killer.
Contributor guide
Research direction
Start with the on_event handler, the CfnResource instance, and the helper.Data assignments shown in the report. Reproduce the failure using the supplied decorated handler and compare it with the direct return value from the simple Lambda. Done means CloudFormation receives both ProductId and ArtifactId as custom-resource attributes without the reported missing-key error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100