Skip to content

BeanTraining/terraform-api-aws-lambda

Repository files navigation

AWS Lambda functions for Terraform API

A project with the structure that supports multi function Rustlang AWS Lambda applications with ⚡ serverless framework ⚡ using Cargo workspaces

✨ features

  • 🦀 Auto-approve API to approve automatically TF workspaces that need human attention.
  • 🛵 Continuous integration testing with GitHub Actions
  • 🚀 Continuous deployment with GitHub Actions
  • 🧪 How to retrieve logs from EFS

📦 install

Install the serverless framework cli.

Then then run the following in your terminal

$ npm ci

npm ci will make sure npm dependencies are installed based directly on your package-lock.json file. This only needs run once.

🧙 how to package locally

$ npx serverless package

The first time you run npx serverless package it will pull down and compile the base set of dependencies and your application. Unless the dependencies change afterwards, this should only happen once, resulting in an out of the box rapid deployment cycle.

Assuming you have aws credentials with appropriate deployment permissions configured (if you already use any existing AWS tooling installed you likely already have this configured), you could impress your friends by creating a project that is born in production and want to deploy the lambda functions using Serverless framework instead of using Terraform.

$ npx serverless deploy

🛵 continuous integration and deployment

This template includes an example GitHub actions configuration file which can unlock a virtuous cycle of continuous integration and deployment ( i.e all tests are run on prs and every push to master results in a deployment ).

Store a AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY used for aws deployment in your repositories secrets https://github.com/{username}/{my-new-service}/settings/secrets

Add your changes to git and push them to GitHub.

Finally, open https://github.com/{username}/{my-new-service}/actions in your browser and grab a bucket of popcorn 🍿

🔫 function triggering using Serverless framework

With your function deployed using Serverless framework, you can now start triggering it using serverless framework directly or the AWS integration you've configured to trigger it on your behalf

$ npx serverless invoke -f hello -d '{"foo":"bar"}'

locally

$ npx serverless invoke local -f hello -d '{"hello":"world"}'

🔫 function triggering using AWS CLI

$ aws lambda invoke --region us-west-2 --function-name hellotfc  --payload 'eyJmb28iOiJiYXIifQo=' output.json

🔬 logs when deployed using the Serverless framework

With your function deployed you can now tail it's logs right from your project

$ npx serverless logs -f hello
$ npx serverless logs -f world

👴 retiring

Good code should be easily replaceable. Good code is should also be easily disposable. Retiring applications should be as easy as creating and deploying them them. The dual of serverless deploy is serverless remove. Use this for retiring services and cleaning up resources.

$ npx serverless remove

ℹ️ additional information

👯 Contributing


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors