Giter VIP home page Giter VIP logo

aws-lambda-terraform-java-dotnet's Introduction

aws-lambda-terraform

This repo demonstrates how to create Lambda's in both Java and Dotnet with the help of Terraform.

I cloned this repo from danielbryantuk who created a super nice starter app (in Java) showing how you can use terraform to create a simple lambda fronted by API Gateway. Thank you Daniel!

This repo is a little more up to date from the original and has the added Dotnet version that follows the same design pattern. So, for those that want to go to Java or Dotnet, this repo should compare the two environments nicely.

Get started

Go to one of the directories dotnet or java and do the following:

To get started simply create a terraform.tfvars file in terraform directory with your AWS account/IAM User details. Your IAM User must have permissions for AWS Lambda and AWS API Gateway.

Run an init in the Terraform directory like so

$ cd terraform
$ terraform init

The contents should follow the template below (with you replacing the info between << >>):

aws_access_key = "<< your IAM user AWS access key >>"
aws_secret_key = "<< your IAM user AWS secret key >>"
region = "<< your chosen region >>"
account_id = "<<your AWS account id>>"

Or instead of the above, you can apply the account key and secret to your terminal session. See ./terraform/main.tf for more details:

export AWS_ACCESS_KEY_ID="<< your IAM user AWS access key >>"
export AWS_SECRET_ACCESS_KEY="<< your IAM user AWS secret key >>"
export AWS_SESSION_TOKEN="<< your session token when needed >>"

From the root of the project run the build_and_deploy.sh script. This compiles the Java application into the helloworld/target directory and runs Terraform to upload and configure the Lambda function and API Gateway.

$ ./build_and_deploy.sh

Manually test your function

After a successful run, something similar to the output below should be visible:

Outputs:

curl = Run the following to test the lambda:
curl -H 'Content-Type: application/json' -X POST -d '{"name": "Emilio"}' https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/beta/helloworld

To test your Lambda deployed behind the API Gateway all you need to do is copy/paste the curl command (minus the curl = part) e.g.

curl -H 'Content-Type: application/json' -X POST -d '{"name": "Emilio"}' https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/beta/helloworld

Rinse and repeat

You can make changes to the Java application and run the build_and_deploy.sh script repeatedly to update the Lambda Function deployed into AWS.

Tidy up when finished!

When you are finished, don't forget to shut your infrastructure down:

$ ./destroy.sh

Disclaimer

Please note: I'm not responsible for any costs incurred within your AWS account :-)

aws-lambda-terraform-java-dotnet's People

Contributors

danielbryantuk avatar randomtask2000 avatar

Stargazers

 avatar

Watchers

 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.