boto3 elasticbeanstalk 客户端 - 无法在 describe_environment_resources

问题描述

来自:AWS::WAFv2::WebACLAssociation ResourceArn for Application Load Balancer in CloudFormation

我有一个现在无法运行的自定义 cloudformation 资源 lambda 函数

最初我什至无法在不指定 region_name 的情况下创建 boto3 客户端。在 cloudformation 中创建此资源时,似乎缺少基本环境变量。

现在我有

import boto3

eb = boto3.client('elasticbeanstalk',region_name='ap-southeast-2')
...
response = eb.describe_environment_resources(
  EnvironmentName=(my eb name)
)

但它抛出了一个我无法追踪的错误:“无法解包不可迭代的 nonetype 对象”

如果我不指定区域,我会收到这个错误[ERROR] 2021-02-16T01:01:27.535Z 90ba5d73-6278-4178-beeb-8cd1df18d704 Unable to construct an endpoint for elasticbeanstalk in region None

我认为根本问题仍然存在,即无法正确创建 cloudformation 的自定义资源以支持 lambda 函数。虽然这适用于其他 VPC。

完整代码可在 https://github.com/qld-gov-au/documentproduction/blob/main/aws/cf/loadbalancerinfo.py 从第 65 行抛出错误

来自 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 

解决方法

发现问题出在我的 requirements.txt 中并引用了 boto3 0.0.1。我已更新为使用正确的版本并重新打包了我的 zip。