How to use lambda function to copy a newly uploaded file from one S3 bucket to another S3 bucket

0

I've tried following multiple tutorials and some articles on aws re:Post to no avail.

zozz
已提问 1 年前486 查看次数
3 回答
0

Can you share more detail on the problem you're having? Is this the guide you used? https://repost.aws/knowledge-center/lambda-copy-s3-files

I assume you are using Amazon EventBridge to trigger the lambda and that your lambda function has a role which enables it to get from the source and write to the destination. Failing that, are the objects very large? If no you may exceed the capabilities of the Lambda function to process the files.

Finally, have you considered using S3 replication? https://docs.aws.amazon.com/AmazonS3/latest/userguide/replication.html

AWS
Alex_K
已回答 1 年前
  • I've created a lambda function with a trigger that detects if an event (the upload of a file) has occurred via the put-post triggers on the source bucket. and the trigger runs a python script that copies the uploaded file to the destination s3 bucket. But when uploading the file, nothing happens. I have to use lambda function (College Project requirement).

  • Can you confirm via CloudWatch/debugging 'print' statements how far the Lambda gets? Does it even trigger? Can it read the source file? Does it fail when trying to write to the destination?

0

Hi,

If you are using an Amazon S3 event notification to sent an event to a Lambda function when an object is created, then Amazon S3 needs permission from the function's resource-based policy to invoke the function. Could you check if it is? Here is an example taken from the AWS Lambda documentation.

{
    "Version": "2012-10-17",
    "Id": "default",
    "Statement": [
        {
            "Sid": "lambda-allow-s3-my-function",
            "Effect": "Allow",
            "Principal": {
              "Service": "s3.amazonaws.com"
            },
            "Action": "lambda:InvokeFunction",
            "Resource":  "arn:aws:lambda:us-east-2:123456789012:function:my-function",
            "Condition": {
              "StringEquals": {
                "AWS:SourceAccount": "123456789012"
              },
              "ArnLike": {
                "AWS:SourceArn": "arn:aws:s3:::my-bucket"
              }
            }
        }
     ]
}

If this was not the reason, could you attach the article or tutorial that you have used?

profile picture
专家
已回答 1 年前
profile picture
专家
已审核 1 个月前
0

I see you configured it on object POST, I have this solution working on "Object Created". Is it working if you trigger in on "all events"? You can actually have a function that does a print(event) only to see if it is triggered and allowed to write into Cloudwach-Logs

nand0l
已回答 1 年前
profile picture
专家
已审核 1 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则