Giter VIP home page Giter VIP logo

terraform-terragrunt-aws-lambda-tutorial's Introduction

Build Status Maintainability codebeat badge

AWS Lambda deployment with Terraform & Terragrunt - Tutorial

This tutorial shows how to deploy a Python function on AWS Lambda with Terraform and Terragrunt.

The Terraform configuration can also:

  • install the required Python dependencies
  • keep track of changes to the code and dependencies to avoid re-deploying an unchanged function

Terragrunt is a wrapper for Terraform which helps to manage multiple environments.

Prerequisites

Optional:

Setup

  • Create an AWS account and get a Access Key ID and Secret Access Key pair (read the docs)
  • Install and configure the AWS CLI (read the docs)
  • Install Terraform (read the docs)
  • Install Python or, with Miniconda or Conda, run:
    $ conda env create -n tflambda -f environment.yml
    $ source activate tflambda
    
    (Python docs)
  • Terragrunt is optional, install it for a more advanced setup (read the docs)

Usage

Running locally

$ cd lambda
$ pip install -r requirements.txt
$ python lambda.py

to view the log output on screen, run:

$ LOG_LEVEL=INFO python lambda.py

Deploying to AWS Lambda with Terraform

Run:

$ cd terraform
$ terraform init
$ terraform apply

If you have multiple AWS profiles and you want to set the profile to use:

$ AWS_PROFILE=myprofilename terraform apply

The Terraform AWS provider offers a number of options to set credentials, check the docs for further details.

To deploy to a specific AWS region (see variables.tf for defaults):

$ terraform apply -var aws_region="eu-west-1"

Deploying to AWS Lambda with Terragrunt

2 sample Terragrunt configurations are provided:

Run:

$ cd terragrunt/eu
$ terragrunt apply

change /eu to /us and repeat to try another region.

AWS profiles selection also applies to Terragrunt:

$ AWS_PROFILE=myprofilename terragrunt apply

Cleaning up

Run:

$ cd terraform
$ terraform destroy

terraform-terragrunt-aws-lambda-tutorial's People

Contributors

edonosotti 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.