Git Product home page Git Product logo

lambda-demo's Introduction

Super Important Lambda Demo

Description: Demo of things Joe learned while messing around with Lambdas

Super_Important_Picture

Background

Addressing need for Lambdas

  • We needed a way to provision certificates in the new AWS account
    • We didn't have Rundeck to help us out
    • There would be more overhead and cost to exploring ECS or EKS
    • Lambdas are usually cheap to run
  • We already have lambdas in production, but no one is currently supporting/owning them from a standardization and deployment perspective

Demo Overview

Lambda Demo Overview

Demo Build Directions

Pre-Flight

Software

  • Install awscli and configure an account named lambda-demo with the default region us-east-1:
    • aws configure --profile lambda-demo
  • Install Docker
  • Install Terraform

Github

Music

  • Start 80s Synthwave Music: make start-music

Building a Lambda Package

  • Docker was necessary because the AWS documentation wants you to provision an Amazon Linux EC2 instance
  • Download/Build the lambda builder container: make docker-init
  • After the build has finished, package the lambda: make lambda-build
    • This will zip the application and dependencies

Create Lambda with Terraform

  • Terraform will create the structure needed to support the lambda in AWS
    • Lambda
    • IAM Role
    • IAM Policy
  • Initialize Terraform: make tf-init
  • Use Terraform to provision new lambda: make tf-apply
    • You will be prompted to review and confirm the changes

Testing the Lambda

  • After terraform has completed, you can invoke the function and its handler: make lambda-invoke
    • Think of the handler as a substitute of main in python

Updating the Lambda

  • You decide you want to make changes to your function, simply go to the lambda folder and edit app.py
  • After making changes, rebuild the lambda packages, upload the lambda, and invoke the function: make lambda-build lambda-upload lambda-invoke or make lambda-refresh

Troubleshooting the Lambda

  • Log into the AWS console for the account you specified in awscli
  • Navigate to the Lambda control panel
  • Click on the function that you just created demo_testservice_stg_useast1_example_com
  • Here you can review the function code
    • Note: If the function is deemed too big by AWS, you will not be able to use this IDE.
  • You can also change the handler to the test_handler specified in app.py
  • Press the Save button on the top right corner, click the empty drop-down menu to the left of the Test button and select Configure test event
  • Give the Event name a name and then press Create
  • You can now press the Test button
  • Review the Execution results in the console to see what happened with the test_handler
  • You can also see more robust logs by pressing the Logs link next to the Execution results

Removing Lambda

  • Destroy lambda resources: make tf-destroy
  • Confirm deletion by submitting yes Sample Destroy Output
$ make tf-destroy
terraform destroy terraform/
data.template_file.lambda_assume_role: Refreshing state...
aws_iam_role.lambda_role: Refreshing state... (ID: demo_testservice_stg_useast1_example_com)
aws_lambda_function.lambda_demo: Refreshing state... (ID: demo_testservice_stg_useast1_example_com)

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  - aws_iam_role.lambda_role

  - aws_lambda_function.lambda_demo


Plan: 0 to add, 0 to change, 2 to destroy.

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

aws_lambda_function.lambda_demo: Destroying... (ID: demo_testservice_stg_useast1_example_com)
aws_lambda_function.lambda_demo: Destruction complete after 5s
aws_iam_role.lambda_role: Destroying... (ID: demo_testservice_stg_useast1_example_com)
aws_iam_role.lambda_role: Still destroying... (ID: demo_testservice_stg_useast1_example_com, 10s elapsed)
aws_iam_role.lambda_role: Destruction complete after 11s
  • Remove docker images: make docker-cleanup

Lessons Learned

  • Lambdas aren't always fun to debug
  • Keep Lambdas small, don't implement more than a few functions
  • Lambdas/Serverless won't fix all problems. It actually introduces new problems too

Additional Thoughts

  • There are a bunch more things that lambdas can do
    • Interface with other AWS resources
    • We didn't even touch on the API Gateway
  • Deployment pipelines need to be figured out for each runtime (python/ruby/nodejs)
  • Terraform is great for provisioning the resources, but not great for updating the lambda after initialization
  • Lambdas are great for monitoring checks

lambda-demo's People

Contributors

jperez3 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

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