Coder Social home page Coder Social logo

aws_sam_sample's Introduction

AWS SAM Sample app

This repository is sample app for AWS SAM (Serverless Application Model).

install sam tool

$ pip install -r requirements.txt

run docker

$ docker-machine start default
$ eval "$(docker-machine env default)"

install npm package

cd src
npm install

run lambda + API gateway server

$ sam local start-api

test

$curl -i http://localhost:3000/1.0/test
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 18
Server: Werkzeug/0.14.1 Python/3.6.2
Date: Wed, 03 Oct 2018 18:56:45 GMT

{"message":"test"}
$curl -i  -X POST  http://localhost:3000/1.0/hello/my_message
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 24
Server: Werkzeug/0.14.1 Python/3.6.2
Date: Wed, 03 Oct 2018 18:56:58 GMT

{"message":"my_message"} 
$ curl -i http://localhost:3000/1.0/not_found
HTTP/1.0 404 NOT FOUND
Content-Type: application/json
Content-Length: 23
Server: Werkzeug/0.14.1 Python/3.6.2
Date: Wed, 03 Oct 2018 18:57:29 GMT

{"message":"404 error"}

session test

set cookie

$ curl -i http://localhost:3000/1.0/test/setSession
HTTP/1.0 200 OK
Set-Cookie: SID=%7B%22status%22%3A%22ok%22%7D.eTkTgF7CmPnvB9WX2f9JLba5qgXjVf969xI6KdXCVmY; Path=/; Expires=Thu, 04 Oct 2018 07:20:09 GMT
Content-Type: application/json
Content-Length: 18
Server: Werkzeug/0.14.1 Python/3.6.2
Date: Wed, 03 Oct 2018 22:34:33 GMT

{"message":"test"}

get cookie

$ curl -i -H "Cookie: SID=%7B%22status%22%3A%22ok%22%7D.eTkTgF7CmPnvB9WX2f9JLba5qgXjVf969xI6KdXCVmY;" http://localhost:3000/1.0/test/getSession
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 27
Server: Werkzeug/0.14.1 Python/3.6.2
Date: Wed, 03 Oct 2018 22:35:19 GMT

{"session":{"status":"ok"}} 

user auth test

valid user

$ curl -i -H "Cookie: SID=%7B%22status%22%3A%22ok%22%7D.eTkTgF7CmPnvB9WX2f9JLba5qgXjVf969xI6KdXCVmY;" http://localhost:3000/1.0/test/user_auth
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 40
Server: Werkzeug/0.14.1 Python/3.6.2
Date: Wed, 03 Oct 2018 22:44:25 GMT

{"user":{"id":1,"username":"test_user"}}

invalid user

$ curl -i http://localhost:3000/1.0/test/user_auth
HTTP/1.0 401 UNAUTHORIZED
Content-Type: application/json
Content-Length: 23
Server: Werkzeug/0.14.1 Python/3.6.2
Date: Wed, 03 Oct 2018 22:44:54 GMT

{"message":"401 error"} 

deployment

sam package --template-file template.yaml --output-template-file serverless-output.yaml --s3-bucket YOUR_DEPLOYMENT_BUCKET --region ap-northeast-1 --profile YOUR_AWS_PROFILE
aws cloudformation deploy --template-file serverless-output.yaml --stack-name YOUR_CLOUDFORMATION_STACK --profile YOUR_AWS_PROFILE --region ap-northeast-1 --capabilities CAPABILITY_IAM 

aws_sam_sample's People

Contributors

isamu avatar

Watchers

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