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
질문됨 일 년 전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
답변함 일 년 전
  • 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
전문가
답변함 일 년 전
profile picture
전문가
검토됨 한 달 전
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
답변함 일 년 전
profile picture
전문가
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠