Hi Folks,
Now everything is PaaSified :)
So today we are going to looking in to creating and deploying AWS Lambda - Python from ZERO.
Here we go...
Step1. Create a new AWS Lambda using AWS portal or AWS CLI
Step 2. Install Python and pip in your local machine
Step 3. Create a new folder in your local machine
Step4. create a new file YOUR_FILE_NAME.py in that folder
Step5. Do some coding in that file
Sample code
Step7. Save the file
Step8. Install boto3 modules for making python function ready
pip install boto3 -t ./
Step9. Make a ZIP package with correct file permissions
Same like step8 you can install any other modules for your code.
Now everything is PaaSified :)
So today we are going to looking in to creating and deploying AWS Lambda - Python from ZERO.
Here we go...
Step1. Create a new AWS Lambda using AWS portal or AWS CLI
Step 2. Install Python and pip in your local machine
Step 3. Create a new folder in your local machine
Step4. create a new file YOUR_FILE_NAME.py in that folder
Step5. Do some coding in that file
Sample code
import json
print('Loading function')
def lambda_handler(event, context):
print("This is from Lambda ")
return "Lambda Executed Successfully !"
Step8. Install boto3 modules for making python function ready
pip install boto3 -t ./
Step9. Make a ZIP package with correct file permissions
cd YOUR-FOLDER-NAME
chmod -R 755 .
zip -r ../myDeploymentPackage.zip .
Step10. Upload myDeploymentPackage.zip in Lambda using AWS portal or AWS CLI
- Open the AWS Lambda console.
- Choose Functions on the navigation pane, and then open your function.
- In the Function code section, expand the Code entry type drop-down list, and then choose Upload a .ZIP file.
- Choose Upload, and then select your .zip file.
- Choose Save.
- Choose Test.
You can also upload your .zip file from the AWS Command Line Interface (AWS CLI) using the update-function-code command.
Step11. Make sure that you have proper settings
Handler should set as YOUR_FILE_NAME.YOUR_HANDLER_METHOD_NAME
For example
If you saved your file as "lambda_function.py" and the handler method is "lambda_handler(event, context)" you should set "lambda_function.lambda_handler" as Handler in settings. Otherwise you will get error.
Same like step8 you can install any other modules for your code.
You are all set... All the best ! Happy Coding...!!