A follow on from: AWS::WAFv2::WebACLAssociation ResourceArn for Application Load Balancer in CloudFormation
I have a custom cloudformation resource lambda function that now fails to run.
Initially I had trouble even getting it to create a boto3 client without specifying a region_name. It seems that the basic environment variables are missing when creating this resource in cloudformation.
Now I have
import boto3
eb = boto3.client('elasticbeanstalk', region_name='ap-southeast-2')
...
response = eb.describe_environment_resources(
EnvironmentName=(my eb name)
)
But it throws an error which I cannot track down: "cannot unpack non-iterable NoneType object"
If I dont specify the region, I get this error:
[ERROR] 2021-02-16T01:01:27.535Z 90ba5d73-6278-4178-beeb-8cd1df18d704 Unable to construct an endpoint for elasticbeanstalk in region None
I think the root issue still exists where cloudformation's custom resource cannot be created properly to support the lambda function. Though this works in other VPCs.
Full code available at https://github.com/qld-gov-au/documentproduction/blob/main/aws/cf/loadbalancerinfo.py Error is thrown from line 65.
Error from CloudWatch:
2021-02-15T21:32:44.855+10:00 [INFO] 2021-02-15T11:32:44.854Z e382e390-b3da-403b-a301-79b0555eedac got event {'RequestType': 'Create', 'ServiceToken': 'xxxx:function:dp-LoadBalancerInfoFunction-DI95WY45K5R2', 'ResponseURL': 'https://cloudformation-custom-resource-response-apsoutheast2.s3-ap-southeast-2.amazonaws.com/arn%3Aaws%3Acloudformation%3Aap-southeast-2%3A456083373251%3Astack/dp/ebe11aa0-6f7f-11eb-baad-0a8329d47ae6%7CLoadBalancerInfoResource%7C7d5e590a-a501-43ae-a79b-9dc62f4fed8b?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210215T113243Z&X-Amz-SignedHeaders=host&X-Amz-Expires=7200&X-Amz-Credential=xxxxxxx%2F20210215%2Fap-southeast-2%2Fs3%2Faws4_request&X-Amz-Signature=xxxxx', 'StackId': 'arn:aws:cloudformation:ap-southeast-2:xxxxx:stack/dp/ebe11aa0-6f7f-11eb-baad-0a8329d47ae6', 'RequestId': '7d5e590a-a501-43ae-a79b-9dc62f4fed8b', 'LogicalResourceId': 'LoadBalancerInfoResource', 'ResourceType': 'Custom::GetEBLoadBalancerArn', 'ResourceProperties': {'ServiceToken': 'arn:aws:lambda:ap-southeast-2:xxxxx:function:dp-LoadBalancerInfoFunction-DI95WY45K5R2', 'EBEnvName': 'dp-Applic-US4NZLOYHZND'}}
2021-02-15T21:32:44.860+10:00 [INFO] 2021-02-15T11:32:44.860Z e382e390-b3da-403b-a301-79b0555eedac Found credentials in environment variables.
2021-02-15T21:32:45.039+10:00 [INFO] 2021-02-15T11:32:45.23Z e382e390-b3da-403b-a301-79b0555eedac Starting new HTTPS connection (1): elasticbeanstalk.ap-southeast-2.amazonaws.com
2021-02-15T21:32:45.060+10:00 [ERROR] 2021-02-15T11:32:45.59Z e382e390-b3da-403b-a301-79b0555eedac cannot unpack non-iterable NoneType object