Giter Site home page Giter Site logo

deploy-aws-lambda-function's Introduction

Dev environment for deploying AWS Lambda Functions via Ansible

Description

Automated deployment of AWS Lambda function using Ansible.

Architecture

Alt

Definitions

What is a AWS Lambda?

AWS Lambda lets you run code without provisioning or managing servers.

What is Ansible?

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications, automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.

Installation requirements

  • Install VirtualBox and Vagrant
  • Clone this repo
  • Drop in AWS Credentials @ config/.aws/credentials folder. The aws credentials need to have permissions to manage AWS Lambda. For more information on AWS IAM refer here

Commands

Start:

$ vagrant up

This does the following:

  • Copies AWS credentials from host to VM
  • Installs Ansible
  • Backs up Ansible hosts file and updates with the one that is provided with the repo.
  • Gathers SSH public keys by executing ssh-keyscan on localhost.
  • Installs python-pip and necessary aws packages.

SSH into the server

$ vagrant ssh

Establish SSH trust

In order to establish password less access to nodes(and host) we need to establish SSH trust. The ssh-addkey.yml playbook uses authorized_key module which will help in configuring ssh password less logins on remote machines. More details on authorized_key module can be found here.

Check to make sure we do not have public RSA key.
$ ls -l .ssh/

We will create a RSA key by the following command

$ ssh-keygen -t rsa -b 2048

Check to make sure we have the id_rsa.pub file present as specified in the ssh-addkey.yml playbook.

Run the ansible play book - ssh-addkey.yml with ask pass option to make sure we are deploying the key to all machines- in this case there is only one machine- localhost.

$ ansible-playbook deploytoLambda/playbooks/ssh-addkey.yml --ask-pass

Now try the ansible ping module to ping the local server with the ask password option.

$ ansible all -m ping

This is should provide the following output.

localhost | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

Deploy Lambda function to AWS lambda using Ansible

Here we are using python code that will backup and tag an EC2 instance.

Alt

cd into src folder and update the file that will be deployed to lambda.

$ cd deploytoLambda/src

cd to playbooks directory once lambda function is ready to be deployed.

$ cd deploytoLambda/playbooks

Update the following variables with respective values

  • LAMBDA_ARN - AWS IAM role with necessary permissions to execute the lambda function
  • INSTANCE_ID - The EC2 instance that is being backed up
  • INSTANCE_NAME- Name of the EC2 instance that is backed up
  • INSTANCE_DESCRIPTION- Description for the image

Run the ansible playbook to deploy Lambda fucntion to AWS Lambda

$ ansible-playbook deploy-lambda-function.yml

This does the following:

  • Zips up the python code
  • Creates a Lambda function in AWS Lambda.

Reference

AWS Lambda

deploy-aws-lambda-function's People

Contributors

shreyassrinath avatar

Stargazers

Joel Agbo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.