[英]module initialization error name 'event' is not defined
I am trying to copy file from one bucket to another through AWS Lamda Function.我正在尝试通过 AWS Lamda 函数将文件从一个存储桶复制到另一个存储桶。 My AWS S3 Trigger Setting
我的 AWS S3 触发器设置
Here is the code --->
这是代码--->
from __future__ import print_function
import boto3
import json
import time
import urllib
print("loadig function")
s3 = boto3.client('s3')
def lambda_handler(event, context):
source_bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key'])
target_bucket = 'destinationstage'
copy_source = {'Bucket': source_bucket, 'Key': key}
try:
print("waiting for the file persist in the source bucket")
waiter = s3.get_waiter('object_exists')
waiter.wait(Bucket=source_bucket, key=key)
print(
"copying the object from the source s3 bucket to destination s3 bucket"
)
s3.copy_object(Bucket=target_bucket, Key=key, CopySource=copy_source)
except Exception as e:
print(e)
print(
"Error getting object {} from bucket {}. Make sure tehy exists in the bucket"
)
raise e
Here is the error message I keep receiving --->这是我不断收到的错误消息 --->
Request ID:
"628ad4ad-3355-492f-8daf-019a6b9c655c"
Function Logs:
START RequestId: 628ad4ad-3355-492f-8daf-019a6b9c655c Version: $LATEST
module initialization error: name 'event' is not defined
END RequestId: 628ad4ad-3355-492f-8daf-019a6b9c655c
REPORT RequestId: 628ad4ad-3355-492f-8daf-019a6b9c655c Duration: 598.71 ms Billed Duration: 600 ms Memory Size: 128 MB Max Memory Used: 67 MB Init Duration: 343.97 ms
module initialization error
name 'event' is not defined
it's just an indentation problem.这只是一个缩进问题。 Change to:
改成:
import boto3
import json
import time
import urllib
print("loadig function")
s3 = boto3.client('s3')
def lambda_handler(event, context):
source_bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key'])
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.