Contact API by using serverless/serverless: Serverless Framework – Build web, mobile and IoT applications with serverless architectures using AWS Lambda, Azure Functions, Google CloudFunctions & more! –.
This manual is running at "dev" stage and "ap-northeast-1" region.
requires Node v4.
$ node -v
v4.2.1
see serverless/provider-account-setup.md at master · serverless/serverless.
$ npm install serverless@0.5.6 -g
$ sls -v
0.5.6
[Notice] Run only Serverless Framework version 0.5.x.
$ git clone https://github.com/naotty/contact-api.git
$ cd contact-api
$ npm install
Create "dev" stage and select "ap-northeast-1" region.
$ sls project create -c true
Add S3 bucket name prefix.
$ vi _meta/variables/s-variables-dev.json
{
"stage": "dev",
+ "bucketNamePrefix": "<your bucket name prefix>"
}
Add SNS topic arn.
$ vi _meta/variables/s-variables-dev-apnortheast1.json
{
"region": "ap-northeast-1",
+ "snsTopicArn": "<your topic arn>"
}
$ sls resources deploy -s dev
$ sls function deploy -s dev
$ sls endpoint deploy -a -s dev
Serverless: Successfully deployed endpoints in "dev" to the following regions:
Serverless: ap-northeast-1 ------------------------
Serverless: POST - v1/contacts - https://hogehoge.execute-api.ap-northeast-1.amazonaws.com/dev/v1/contacts
Serverless: OPTIONS - v1/contacts - https://hogehoge.execute-api.ap-northeast-1.amazonaws.com/dev/v1/contacts
$ vi client/dist/index.html
$.ajax({
- url: "<your api gateway endpoint>",
+ url: "https://hogehoge.execute-api.ap-northeast-1.amazonaws.com/dev/v1/contacts",
$ sls client deploy -s dev
Url is http://<your bucket name prefix>-dev.s3-website-ap-northeast-1.amazonaws.com
.
$ sls project remove -s dev
And remove API Gateway resources and Lambda functions, S3 bucket manually.
MIT