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