简体   繁体   English

模块初始化错误名称“事件”未定义

[英]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.

相关问题 带有dynamodb的AWS Lambda错误(模块初始化错误:未定义名称&#39;dynamodb&#39;) - AWS Lambda error (module initialization error: name 'dynamodb' is not defined) with dynamodb Python class 变量初始化中的错误“名称'A'未定义” - Python Error "name 'A' is not defined" in class variable initialization 在同一模块中已经定义名称时,名称未定义错误 - Name not defined error when name is already defined in the same module 在python模块中未定义的名称 - name not defined in python module Python错误导入模块熊猫“未定义名称&#39;GET&#39;” - Python error importing module pandas “name 'GET' is not defined” 导入后Python getopt模块错误“NameError:名称&#39;opts&#39;未定义” - Python getopt module error "NameError: name 'opts' is not defined" after importing 修复文件“第1行的错误,在<module> NameError:名称“帐户”未定义</module> - fix the error of File " line 1, in <module> NameError: name 'Account' is not defined 名称错误-名称未定义…但是它是 - Name Error - Name is not defined… but it is Python 自定义模块名称未定义 - Python custom module name not defined 我正在将一个模块导入另一个模块以在 tkinter 中创建一个 treeview 但它向我显示错误 NameError: name 'treeview' is not defined - I'm importing a module to another module to make a treeview in tkinter but it is showing me a error NameError: name 'treeview' is not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM