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
feita há um ano486 visualizações
3 Respostas
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
respondido há um ano
  • 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
ESPECIALISTA
respondido há um ano
profile picture
ESPECIALISTA
avaliado há um mês
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
respondido há um ano
profile picture
ESPECIALISTA
avaliado há um mês

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas