Code Monkey home page Code Monkey logo

lambda-sam-schedule's Introduction

Lambda schedule example by AWS SAM and Terraform

  • Setup Lambda with schedule event by SAM
  • development using SAM and deploy using Terraform without S3

Setup

# install AWS CLI, Docker and SAM CLI
brew install awscli
brew cask install docker
brew install aws-sam-cli
# install python env tools
brew install pyenv pipenv
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
echo 'eval "$(pipenv --completion)"' >> ~/.bash_profile
echo 'export PIPENV_VENV_IN_PROJECT=true' >> ~/.bash_profile
source ~/.bash_profile
# install python packages
cd sam-app/
pipenv install
pipenv install --dev
pipenv shell
python --version     # make sure you see Python 3.7.2 or later
# if you want to initialize
# sam init --name new-app --location sam-app --runtime python3.7
# cd new-app
# pipenv --python 3.7
# pipenv install -r src/requirements.txt
# pipenv install --dev -r src/requirements_dev.txt
# note: template.yaml default is python3.6

Test

cd sam-app/
pipenv shell
# run unit test
python -m pytest tests/ -v

Build and Run Locally

cd sam-app/
# the build command create files in
# .aws-sam/build/HelloWorldFunction/
sam build --use-container --region ap-northeast-1
# run lambda
sam local invoke HelloWorldFunction --event event.json

Deploy Terraform Module

cd example
# deploy sample code
terraform plan
terraform apply

Note: how to generate event.json

# to use Constant (JSON text)
# "{\"event_input\":\"something\"}"
# to generate cloudwatch schedule matched event
sam local generate-event cloudwatch scheduled-event
# the SAM init default event.json is generated by the below
sam local generate-event apigateway aws-proxy

Reference


the_below_is_auto_generated_by_terraform-docs

Inputs

Name Description Type Default Required
app_name the app name string "lambda_schedule_test" no
cloudwatch_schedule CloudWatch Events Schedule expression string "rate(5 minutes)" no

Outputs

Name Description
lambda_arn Lambda arn

lambda-sam-schedule's People

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.