Giter VIP home page Giter VIP logo

backend-template's Introduction

Example

In addition to a basic Lambda function and Express server, the example directory includes a Swagger file, CloudFormation template with Serverless Application Model (SAM), and helper scripts to help you set up and manage your application.

Steps for running the example

This guide assumes you have already set up an AWS account and have the latest version of the AWS CLI and AWS SAM installed.

  1. From your preferred project directory:
  git clone https://github.com/vendia/serverless-express.git && cd serverless-express/examples/basic-starter-api-gateway-v2-typescript
  1. Update the config section of package.json with your s3BucketName and region (optionally, change the cloudFormationStackName). If the bucket you specify does not yet exist, the next step will create it for you.
  2. (optional: domain) If you want to use a custom domain name for your application/API, specify it in the config.domain section of package.json. This example assumes the domain is registered in Route53 in the same account you're deploying the example to.
  3. Run npm run setup - this installs the node dependencies, creates an S3 bucket (if it does not already exist), packages and deploys your serverless Express application to AWS Lambda, and creates an API Gateway proxy API.
  4. (optional: domain) If you specify a domain, the example will create an SSL Certificate via Amazon Certificate Manager; create an API Gateway Domain Name record which maps the domain to the API and Stage; and create a Route53 HostedZone and RecordSet with an A record pointing at the API Gateway Domain Name's CloudFront Distribution.
    1. During deployment you should receive an email at one of the registered email addresses for the domain. Approve the SSL Certificate by clicking the link in the email. The stack creation will pause while waiting for this approval.
    2. Wait for stack creation to complete and update Route53 Domain Name to use the Name Servers from the created Hosted Zone NS Record (don't include the trailing '.') via the AWS console.
    3. It may take several hours before the DNS records propagate.
  5. After the setup command completes, open the AWS CloudFormation console https://console.aws.amazon.com/cloudformation/home and switch to the region you specified. Select the ServerlessExpressStack stack (or the stack name you specified for cloudFormationStackName), then click the ApiUrl value under the Outputs section - this will open a new page with your running API. The API index lists the resources available in the example Express server (app.js), along with example curl commands.
  6. (optional) To enable the invoke-lambda package.json script: copy the LambdaFunctionName from the CloudFormation Outputs and paste it into the package.json config's functionName property. Run npm run invoke-lambda to invoke the Lambda Function with the payload specified in api-gateway-event.json.

See the sections below for details on how to migrate an existing (or create a new) Node.js project based on this example. If you would prefer to delete AWS assets that were just created, simply run npm run delete-stack to delete the CloudFormation Stack, including the API and Lambda Function. If you specified a new bucket in the config command for step 1 and want to delete that bucket, run npm run delete-bucket.

Creating or migrating a Node.js project based on the example

To use this example as a base for a new Node.js project:

  1. Copy the files in the examples/basic-starter-api-gateway-v2-typescript directory into a new project directory (cp -r ./examples/basic-starter-api-gateway-v2-typescript ~/projects/my-new-node-project). If you have not already done so, follow the steps for running the example (you may want to first modify some of the resource names to something more project-specific, eg. the CloudFormation stack, Lambda function, and API Gateway API).
  2. After making updates to app.js, simply run npm run package-deploy.

To migrate an existing Node server:

  1. Copy the following files from this directory: api-gateway-event.json, sam-template.yaml, and lambda.js. Additionally, copy the scripts and config sections of example/package.json into your existing package.json - this includes many helpful commands to manage your AWS serverless assets and perform basic local simulation of API Gateway and Lambda. If you have not already done so, follow the steps for running the example.
  2. From your existing project directory, run
npm install --save @vendia/serverless-express
  1. Modify lambda.ts to import your own server configuration (eg. change require('./app') to require('./server')). You will need to ensure you export your app configuration from the necessary file (eg. module.exports = app). This library takes your app configuration and listens on a Unix Domain Socket for you, so you can remove your call to app.listen().
  2. Modify the CodeUri property of the Lambda function resource in sam-template.yaml to point to your application directory (e.g. CodeUri: ./src). If you are using a build tool (e.g. Gulp, Grunt, Webpack, Rollup, etc.), you will instead want to point to your build output directory.
  3. Run npm run package-deploy.

To perform a basic, local simulation of API Gateway and Lambda with your Node server, update api-gateway-event.json with some values that are valid for your server (httpMethod, path, body etc.) and run npm run local.

If you need to make modifications to your API Gateway API or other AWS resources, modify sam-template.yaml and run npm run package-deploy.

Node.js version

This example was written against Node.js 12

Development

To update this example against the latest local changes to @vendia/serverless-express:

npm i ../..
npm run build
npm run local

backend-template's People

Contributors

victorsoares96 avatar renovate[bot] avatar

Watchers

 avatar

backend-template's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency @types/aws-lambda to v8.10.143
  • Update dependency axios to v1.7.5
  • Update dependency config to v3.3.12
  • Update dependency dayjs to v1.11.13
  • Update dependency express-fileupload to v1.5.1
  • Update dependency sharp to v0.33.5
  • Update dependency @types/validator to v13.12.1
  • Update dependency eslint-plugin-prettier to v5.2.1
  • Update dependency husky to v9.1.5
  • Update dependency ts-jest to v29.2.5
  • Update dependency typescript to v5.5.4
  • Update dependency winston to v3.14.2
  • Update typescript-eslint monorepo to v8 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
dockerfile
Dockerfile
  • node 20
  • node 20
github-actions
.github/workflows/cd.yml
  • actions/checkout v4
  • actions/setup-node v4
  • aws-actions/setup-sam v2
  • aws-actions/configure-aws-credentials v4
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-node v4
  • codecov/codecov-action v4
npm
package.json
  • @aws-sdk/client-cloudfront ^3.582.0
  • @aws-sdk/client-s3 3.587.0
  • @vendia/serverless-express 4.12.6
  • axios 1.7.2
  • bcryptjs 2.4.3
  • body-parser 1.20.2
  • celebrate 15.0.3
  • class-validator 0.14.1
  • compression 1.7.4
  • config 3.3.11
  • cors 2.8.5
  • cross-env 7.0.3
  • dayjs 1.11.11
  • dotenv 16.4.5
  • ejs 3.1.10
  • escape-html 1.0.3
  • express 4.19.2
  • express-async-errors 3.1.1
  • express-fileupload 1.5.0
  • jsonwebtoken 9.0.2
  • mime-types ^2.1.35
  • mysql2 3.10.0
  • node-cache 5.1.2
  • reflect-metadata 0.2.2
  • sharp ^0.33.4
  • source-map-support 0.5.21
  • sqlite3 ^5.1.6
  • tslib 2.6.2
  • typeorm 0.3.20
  • uuid ^9.0.1
  • winston 3.13.0
  • winston-loki 6.1.2
  • @faker-js/faker 8.4.1
  • @types/aws-lambda 8.10.138
  • @types/bcryptjs 2.4.6
  • @types/compression 1.7.5
  • @types/config 3.3.4
  • @types/cors 2.8.17
  • @types/ejs 3.1.5
  • @types/escape-html 1.0.4
  • @types/express 4.17.21
  • @types/express-fileupload 1.5.0
  • @types/jest 29.5.12
  • @types/jsonwebtoken 9.0.6
  • @types/mime-types ^2.1.4
  • @types/node 20.12.13
  • @types/supertest 6.0.2
  • @types/uuid ^9.0.8
  • @types/validator 13.11.10
  • @typescript-eslint/eslint-plugin 7.11.0
  • @typescript-eslint/parser 7.11.0
  • aws-lambda 1.0.7
  • babel-plugin-module-resolver 5.0.2
  • babel-plugin-transform-typescript-metadata 0.3.2
  • commitizen 4.3.0
  • commitizen-emoji 1.0.5
  • cross-var 1.1.0
  • eslint 8.57.0
  • eslint-config-airbnb-base 15.0.0
  • eslint-config-airbnb-typescript 18.0.0
  • eslint-config-prettier 9.1.0
  • eslint-plugin-import 2.29.1
  • eslint-plugin-jest 28.5.0
  • eslint-plugin-prettier 5.1.3
  • husky 9.0.11
  • jest 29.7.0
  • lint-staged 15.2.5
  • prettier 3.2.5
  • supertest 7.0.0
  • ts-jest 29.1.4
  • ts-node 10.9.2
  • ts-node-dev 2.0.0
  • tsc-alias 1.8.10
  • tsconfig-paths 4.2.0
  • typescript 5.4.5
  • node >=20.x.x <=21.x.x
  • npm >=10.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

api not start

fix path issue when build in log.util.ts specific in: projectName variable

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.