我在执行aws lambda函数时遇到错误问题,该函数是“无法导入模块'custom_resource_lambda':没有名为cfnresponse的模块”。我看到了一种情况,但解决方案是将运行时python版本更改为2.7,但对我不起作用。请让我知道我在做什么错。干杯
import json
import boto3
import cfnresponse
from common_helpers.constants_v2 import LOGGER_NAME
import os
import logging
DEBUG_MODE = os.getenv('DEBUG_MODE', 'false')
ENV_NAME = os.getenv('COMPUTE_ENVIRONMENT_NAME')
batch_client = boto3.client('batch')
# Configure logging
LOGGER = logging.getLogger(LOGGER_NAME)
if DEBUG_MODE == 'true':
LOGGER.setLevel(logging.DEBUG)
else:
LOGGER.setLevel(logging.INFO)
def handler(event, context):
LOGGER.info("Received event: " + json.dumps(event))
try:
if event['RequestType'] == 'Delete':
send(event, context, cfnresponse.SUCCESS)
return
response = batch_client.describe_compute_environments(
computeEnvironments=[
ENV_NAME,
],
)
compute_env_details = response.get('computeEnvironments')
cluster_arn = compute_env_details[0]['ecsClusterArn']
cluster_name = cluster_arn.split('/')[1]
data = dict(Data=dict(
ClusterArn=cluster_arn,
ClusterName=cluster_name))
event.update(data)
cfnresponse.send(event, context, cfnresponse.SUCCESS)
except BaseException as e:
send(event, context, cfnresponse.FAILED)
答案 0 :(得分:0)
您需要将库安装在lambda的根目录中(与python版本无关)
为此,您需要在lambda函数的根目录中运行此命令
pip install cfnresponse -t .
安装完成后,压缩您的lambda并再次上传。错误应该消失了。