The purpose of this post is nothing else just make an overview of interaction between AWS Lambda and AWS S3. You can easily search on the Internet about the information about what AWS Lambda and AWS S3 are, I just wanna make it understandable in an easy way like below:
- AWS Lambda is a PaaS solution. Imagine that you are a developer, you write a bunch of code line to do something and you need an environment to test it. AWS provide that enviroment for you. For example, write your code in local or in any AWS instance, create a zip file including your source code and its dependencies then upload it to the AWS Lamda service. In the AWS Lamda service, you can test your code monotonely or in the interaction with other services such as S3, Kinesis, DynamoDB, etc. Altenatively, you can copy/paste directly your source code into AWS Lambda GUI. The point here that you do not need to take care about the necessary resources (CPU, RAM, network, etc.) to run your code, AWS Lambda will do it for you.
-
AWS S3 is a storage solution. It is simple a storage, which is out there somewhere that you can use to store whatever you want.
In this post, I am going to show you the prototype of interaction between AWS Lambda and AWS S3. The testing procedure is below:
- Create an Ubuntu instance.
Create two buckets in the AWS S3:
- Source bucket called “tutj” where I store an image called “cover.jpeg”
Picture 1. cover.jpeg
- Destination bucket called “tutjresized” where I am going to nothing else just copy that image “cover.jpeg”. Actually, you can do anything you want with image (resize, change color, etc.) then store it to the destination bucket.
Picture 2. AWS S3 buckets
- Access to that instance, install AWS CLI and use it to create a Lambda function:
Function-name: “CopyImage”
Source code and dependencies: “/home/ubuntu/CopyImage.zip”
Handler: “CopyImage.handler”. It will be called each time AWS S3 triggers AWS Lambda.
Profile: “tutj”. The AWS User.
$ sudo aws lambda create-function --region us-east-1 --function-name CopyImage –zip-file fileb:///home/ubuntu/CopyImage.zip –role arn:aws:iam::856421922278:role/lambda-s3-execution-role --handler CopyImage.handler --runtime python2.7 --profile tutj --timeout 10
Picture 3. AWS Lambda CopyImage function
- After testing the “CopyImage” function, the “cover.jpeg” is moved to the new destination bucket “tutjresized”.
Picture 4. Image in the destination bucket
For more information, follow this below link on AWS:
http://docs.aws.amazon.com/lambda/latest/dg/with-s3.html
Comments