Step 2 – Configuring S3 bucket policy
In ‘Block Public Access settings for this bucket’ section disable “block all public access”. You will get a warning that the bucket and its objects might become public. Agree to the warning. (Note: we are making this bucket public only for this project, it is not recommended to make an S3 bucket public if not needed).
Leave all other settings as default and create bucket. Similarly, create another bucket named ‘serverless-bucket-processed-images’ with the same region. This bucket will be used to store the processed images. Although we enabled public access while creating the buckets, we still need to attach a bucket policy to access the objects stored in it. (Policies in AWS are JSON documents which defines the permissions for performing actions on a certain resource.)
Go to your source bucket and then click on Permissions tab. Scroll to Bucket Policy tab. Click Edit. You will be redirected to the policy editor. Click on policy generator.
Enter the following settings:
- Type of policy: S3 Bucket Policy
- Effect:Allow
- Principal: *
- Actions: GetObject
- Amazon Resource Name (ARN): arn:aws:s3:::SOURCE_BUCKET_NAME/*
SOURCE_BUCKET_NAME is the name of the bucket used for uploading the images.
Click Add Statement and then generate policy. Copy the JSON object.
Paste it in the policy editor and then save changes.
Follow same steps to attach a policy to the processed images S3 bucket. The policy settings for destination bucket are:
- Type of policy: S3 Bucket Policy
- Effect:Allow
- Principal: *
- Actions: GetObject, PutObject, and PutObjectAcl
- Amazon Resource Name (ARN): arn:aws:s3:::DESTINATION_BUCKET_NAME/*
DESTINATION_BUCKET_NAME is the name of the bucket used for storing processed images.
Serverless Image Processing with AWS Lambda and S3
AWS S3 (Simple Storage Service) is a cloud data storage service. It is one of the most popular services of AWS. It has high scalability, availability, security and is cost effective. S3 has different storage tiers depending on the use case. Some common use cases of AWS S3 are:
- Storage: It can be used for storing large amounts of data.
- Backup and Archive: S3 has different storage tiers based on how frequent the data is accessed which can be used to backup critical data at low costs.
- Static website: S3 offers static website hosting through HTML files stored in S3.
- Data lakes and big data analytics: Companies can use AWS S3 as a data lake and then run analytics on it for getting business insights and take critical decisions.