Copy Object Between Two S3 Buckets Using a Lambda Function

, , Comments Off on Copy Object Between Two S3 Buckets Using a Lambda Function

    1. Create a bucket called, “source12282016” in Northern California.
    2. Create a bucket called, “destination12282016” in Northern California.
    3. Create an SNS topic called, “sourcebucket12282016-fanout” in Northern California. Note that you will need the resource name of the topic plus the name of the source bucket.
{
 "Version": "2012-10-17"
 , "Statement": [
 {
 "Effect": "Allow"
 , "Action": [
 "logs:CreateLogGroup"
 , "logs:CreateLogStream"
 , "logs:PutLogEvents"
 ]
 , "Resource": "arn:aws:logs:*:*:*"
 }
 , {
 "Effect": "Allow"
 , "Action": [
 "s3:GetObject"
 ]
 , "Resource": [
 "arn:aws:s3:::source12282016/*"
 ]
 }
 , {
 "Effect": "Allow"
 , "Action": [
 "s3:PutObject"
 ]
 , "Resource": [
 "arn:aws:s3:::destination12282016/*"
 ]
 }
 ]
}
    1. Associate an, “event” with the source bucket.

    1. Create a policy for the Lamda function that will be created in subsequent steps. Use the source and destination bucket names accordingly.
{
 "Version": "2012-10-17",
 "Statement": [
 {
 "Effect": "Allow",
 "Action": [
 "logs:CreateLogGroup",
 "logs:CreateLogStream",
 "logs:PutLogEvents"
 ],
 "Resource": "arn:aws:logs:*:*:*"
 },
 {
 "Effect": "Allow",
 "Action": [
 "s3:GetObject"
 ],
 "Resource": [
 "arn:aws:s3:::source12282016/*"
 ]
 },
 {
 "Effect": "Allow",
 "Action": [
 "s3:PutObject"
 ],
 "Resource": [
 "arn:aws:s3:::destination12282016/*"
 ]
 }
 ]
}
    1. Create a role and attach the preceding policy to the role.

    1. Create the Lamda function. Note to skip to and select, “Configure Function”. In the next step we will scroll towards the bottom of the page to attach the role.

    1. Still on the page, we will now associate the role to the Lambda funciton.

    1. Subscribe the Lambda function to the SNS topic created previously.