Skip to content

savankoradiya/python3_aws_lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Executing commands on EC2 using AWS Lambda

About

Execute commands or scripts on Linux instances by using SSH and aws lambda when flie upload in s3 bucket.

Create S3 Bucket

Open AWS Console and Select S3

title

Click on Create Bucket

title

Give it a name, select region then click next through each step

title

title

title

title

Create Ubuntu 16.04 Instance

Open AWS Console and Select ec2

title

Click on Launch Instance

title

Select Ubuntu Server 16.04

title

Choose an Instance Type and click next throught each step

title

title

title

title

title

Create User and Roles

Open AWS Console and Select IAM

title

Click on users

title

Click on Add User

title

Add User name and check Programmatic access and click next and Click on create user

title

Reopen users and Click on Roles

title

Select Amazon services and lambda click next

title

Search lambda and check AWSLambdaExecute

title

Add Role Name and click create role

title

Click on Add inline policy

title

Search DescribeInstances and select DescribeInstances click on Review Policy

title

Add Name and click on Create Policy

title

title

Create Lambda Package

Install python 3.6 in your machine or ec2 instance

Install virualenv

pip3 install virtualenv

Create Virtualenv

virtualenv demo

Activate your virtual environment

source demo/bin/activate

Install Required Packages

pip3 install boto3
pip3 install paramiko

Go to demo/lib/python3.6/site-packages

Create zip file

zip -r code_lambda.zip .

Add your Code Files

zip -r code_lambda.zip code_lambda.py

Create Lambda

Open AWS Console and Select lambda

title

Click on Create Function

title

Click on Blueprints and search python3 you will find Hello-World-python3 select that

title

Add Name and Select Existing role which we create earlier and click on Create Function

title

Click on S3

title

Select your Bucket

Add Prefix folder name where you storing your images in s3 bucket

Add sufix like .jpg,.mp4 etc ..

Click on Create Function

title

Select Upload .zip file and Select zip file which we created earlier and click on save button

title

In Handler you need to add "your file name"."your function name"

title

Set Timeout according your code execution

title

Put your private/public Key inside "key" folder name on s3 bucket

Click on Test button

title

Releases

No releases published

Packages

No packages published

Languages