Skip to content

ricardomozartlino/serverless-typescript-complete-sample

 
 

Repository files navigation

Serverless Typescript complete sample project

serverless Build Status Coverage Status

Welcome to Ricardo serverless typescript aws sample project.

Installation

npm install

To run

This project use serverless-offline to run the project locally.

sls offline start --port=3001

If you don't have serverless installed globally, you can run this one:

./node_modules/serverless/bin/serverless.js offline start --port=3001

Deploy

Requirements to deploy

  • Mongodb Server
  • VPC(securityGroup and subnet) with access to mongodb
  • deployment bucket (bucket to deploy the lambda code)
  • An aws user with the following privileges: iam, lambda, apigateway, log, event and s3.
sls deploy --verbose

You can test your api by taking the endpoint in the log at the end of the deploy

Stack Outputs
ServiceEndpoint: https://xxxxxxx.execute-api.sa-east-1.amazonaws.com/dev

note: You must change de custom.yml file to update mongo_host, securityGroup, subnet, accountId and deployment bucket from your aws account.

Mongodb

There are two indexes to be create

partners.createIndex({ document: 1 }, { unique: true });
partners.createIndex( { 'coverageArea' : "2dsphere" } )

Run unit and integration tests

To run all test

npm test

Save partner

curl:

curl --location --request POST 'https://xxxxxxx.execute-api.sa-east-1.amazonaws.com/dev/partners' \
--header 'Content-Type: application/json' \
--data-raw '{
  "tradingName": "Partner store - Pinheiros",
  "ownerName": "partner name",
  "document": "1432132123891/0001",
  "coverageArea": {
    "type": "MultiPolygon",
    "coordinates": [
      [[[30, 20], [45, 40], [10, 40], [30, 20]]],
      [[[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]]
    ]
  },
  "address": {
    "type": "Point",
    "coordinates": [-46.57421, -21.785741]
  }
}'

GET Partner

curl:

curl --location --request GET 'https://xxxxxxx.execute-api.sa-east-1.amazonaws.com/dev/partners/91e87cbc-8e2f-4c87-902a-c0c3d239c20a'

Get Partners by coordinates

curl:

curl --location --request GET 'https://xxxxxxx.execute-api.sa-east-1.amazonaws.com/dev/partners/latitude/20/longitude/30'

Contributing

About

test zé delivery

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.9%
  • JavaScript 1.1%