@@ -19,15 +19,20 @@ It handles an AWS Lambda function that copies an object when it appears in a S3
19
19
20
20
## Using the code
21
21
22
- * You can select the destination bucket name changing the value of ` DESTINATION_BUCKET ` variable in the code.
22
+ * You can select the destination bucket name using an AWS Lambda environment variable: ` TARGET_BUCKET `
23
23
24
24
* Access the AWS console.
25
25
26
26
* Create a S3 bucket for the source and another S3 bucket for the target.
27
27
28
- * Create an IAM Policy: ex. ` Policy-VM -buckets `
28
+ * Create an IAM Policy: ex. ` Policy-my -buckets `
29
29
30
- Content of the IAM policy:
30
+ Changing:
31
+
32
+ * ` sourcebucket ` to the name of your source bucket.
33
+ * ` targetbucket ` to the name of your target bucket.
34
+
35
+ Content of the IAM policy:
31
36
32
37
``` bash
33
38
{
@@ -39,7 +44,7 @@ It handles an AWS Lambda function that copies an object when it appears in a S3
39
44
" s3:GetObject"
40
45
],
41
46
" Resource" : [
42
- " arn:aws:s3:::sourcevm /*"
47
+ " arn:aws:s3:::sourcebucket /*"
43
48
]
44
49
},
45
50
{
@@ -48,11 +53,10 @@ It handles an AWS Lambda function that copies an object when it appears in a S3
48
53
" s3:PutObject"
49
54
],
50
55
" Resource" : [
51
- " arn:aws:s3:::targetvm /*"
56
+ " arn:aws:s3:::targetbucket /*"
52
57
]
53
58
},
54
59
{
55
- " Sid" : " Stmt1430872844000" ,
56
60
" Effect" : " Allow" ,
57
61
" Action" : [
58
62
" cloudwatch:*"
@@ -62,7 +66,6 @@ It handles an AWS Lambda function that copies an object when it appears in a S3
62
66
]
63
67
},
64
68
{
65
- " Sid" : " Stmt1430872852000" ,
66
69
" Effect" : " Allow" ,
67
70
" Action" : [
68
71
" logs:*"
@@ -75,15 +78,15 @@ It handles an AWS Lambda function that copies an object when it appears in a S3
75
78
}
76
79
```
77
80
78
- * Create a role: ` Role-VM -buckets ` .
81
+ * Create a role: ` Role-my -buckets ` .
79
82
80
- This role uses the policy ` Policy-VM -buckets `
83
+ This role uses the policy ` Policy-my -buckets `
81
84
82
85
* Create an AWS lambda function.
83
86
* Name: ` <LAMBDA_NAME> `
84
- * Runtime: ` Python 3.6 `
87
+ * Runtime: ` Python 3.8 `
85
88
* Handler: ` lambda_function.lambda_handler `
86
- * Role: ` Role-VM -buckets `
89
+ * Role: ` Role-my -buckets `
87
90
* The triggers:
88
91
* ` S3 `
89
92
* Bucket: ` <BUCKET_NAME> `
@@ -93,14 +96,15 @@ It handles an AWS Lambda function that copies an object when it appears in a S3
93
96
* ` Amazon CloudWatch `
94
97
* ` Amazon CloudWatch Logs `
95
98
* ` Amazon S3 `
96
- * Lambda obtained information from the policy statements: ` Managed policy Policy-VM-buckets ` :
97
- * ` s3:GetObject ` --> ` Allow: arn:aws:s3:::sourcevm/* `
98
- * ` s3:DeleteObject ` --> ` Allow: arn:aws:s3:::sourcevm/* `
99
- * ` s3:PutObject ` --> ` Allow: arn:aws:s3:::targetvm/* `
99
+ * Lambda obtained information from the policy statements: ` Managed policy Policy-my-buckets ` :
100
+ * ` s3:GetObject ` --> ` Allow: arn:aws:s3:::sourcebucket/* `
101
+ * ` s3:PutObject ` --> ` Allow: arn:aws:s3:::targetbucket/* `
100
102
* Basic Settings for the lambda function:
101
103
* Memory (MB): ` 1024 `
102
104
* Timeout: ` 10 sec `
103
105
106
+ * Create the AWS Lambda environment variable ` TARGET_BUCKET ` and set its value to the name of your target bucket.
107
+
104
108
* Write the code.
105
109
106
110
The content of ` lambda_function.py ` file.
@@ -114,3 +118,14 @@ It handles an AWS Lambda function that copies an object when it appears in a S3
114
118
Copy a file in the source S3 bucket.
115
119
116
120
The object from the source S3 bucket should be copied to the target S3 bucket.
121
+
122
+ You should see the next messages in the log:
123
+
124
+ ``` bash
125
+ " From - bucket:: <SOURCE_BUCKET_NAME>"
126
+ " From - object: <SOURCE_FILE_NAME>"
127
+ " To - bucket: <TARGET_BUCKET_NAME>"
128
+ " To - object: <TARGET_FILE_NAME>"
129
+ " Copying object ..."
130
+ " Copied"
131
+ ```
0 commit comments