Chapter 2: Working with the AWS Serverless Platform
Solution for Activity 3: Setting up a Mechanism to Get an Email Alert When An Object is Uploaded into an S3 Bucket
Go to the AWS S3 service and click on Create bucket.
Provide a Bucket name and select the region where the S3 bucket will be created. Click on Next. Note that the bucket name can't be duplicated.
If you want to change any configuration, you can do it here. Click on Next.
Now, you can change the settings related to the security of the S3 bucket. If you want to allow public access to the S3 bucket, you can uncheck the options here. Click on Next.
Review all of the configuration settings. If you want to change anything, you can go back. Alternatively, click on Finish and your bucket should be created successfully.
Go to the Lambda function that we created in the earlier exercise. Add S3 as a trigger under the Lambda configuration section:
Figure 2.54: Lambda configuration window
Click on Configuration required and add the required details related to S3 bucket configuration, mainly the bucket name. Keep the rest of the settings as default:
Figure 2.55: Configure triggers window
Click on Add to add that S3 bucket as a trigger to execute the Lambda function:
Figure 2.56: Window showing S3 bucket being added as a trigger
Click on Save to save the changes to the Lambda function:
Figure 2.57: Window showing S3 bucket getting saved
Also, the email message will have changed in the Lambda code to reflect our activity. See line # 8 in the following screenshot. You can customize it based on your needs:
Figure 2.58: Window showing code of index.js
Now, upload a new sample file to the S3 bucket. You should see an email alert in your mailbox.
Go back to the Amazon S3 service, click on the bucket name, and click on the Upload button.
Click on Add files and select the file that you want to load into the S3 bucket. Click on Next.
Set the file level permissions. Click on Next.
Select the storage class. You can continue with the default option. Click on Next.
Review the configuration and click on Upload.
The file should be uploaded successfully:
Figure 2.59: Overview section of Amazon S3
Once the file has been uploaded, go to your mailbox and you should see an email alert:
Figure 2.60: Output showing a new object being uploaded to the S3 bucket
This concludes our activity.