Skip to content

Commit 0788f12

Browse files
committed
Added Lambda environment variable
1 parent 5f48b33 commit 0788f12

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

awslambdas3move/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ It handles an AWS Lambda function that moves an object when it appears in a S3 b
1919

2020
## Using the code
2121

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`
2323

2424
* Access the AWS console.
2525

@@ -105,6 +105,8 @@ It handles an AWS Lambda function that moves an object when it appears in a S3 b
105105
* Memory (MB): `1024`
106106
* Timeout: `10 sec`
107107

108+
* Create the AWS Lambda environment variable `TARGET_BUCKET` and set its value to the name of your target bucket.
109+
108110
* Upload the Java JAR file.
109111

110112
Artifact:

awslambdas3move/src/main/java/example/S3MoveHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
public class S3MoveHandler implements RequestHandler<S3Event, String> {
2222

23-
private static final String DESTINATION_BUCKET = "targetbucket10"; // Destination bucket name
24-
2523
public String handleRequest(S3Event s3Event, Context context) {
2624
String sourceBucketName; // Source bucket name
2725
String sourceKeyName; // Source key name
@@ -40,7 +38,12 @@ public String handleRequest(S3Event s3Event, Context context) {
4038
sourceKeyName = record.getS3().getObject().getKey(); // Name doesn't contain any special characters
4139

4240
// Destination Bucket Name
43-
destinationBucketName = DESTINATION_BUCKET;
41+
destinationBucketName = System.getenv("TARGET_BUCKET");
42+
43+
if (destinationBucketName == null || destinationBucketName.isEmpty()) {
44+
logger.log("Error: TARGET_BUCKET Lambda environment variable does not exist!!");
45+
System.exit(1);
46+
}
4447

4548
// Destination File Name
4649
destinationKeyName = sourceKeyName;

0 commit comments

Comments
 (0)