Skip to content

RyanTimesTen/serverless-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless example

Setup

This project uses the express web framework, and deploys it to AWS using serverless. In order to run commands locally and run the server locally, you need to install dependencies:

yarn install

You can then run the server in localdev with:

yarn dev

Deploy to AWS

Before you can deploy to AWS, you need to configure your AWS credentials. This only needs to be done once per-project. It's recommended to use aws-vault to securely store AWS credentials.

To generate a new set of credentials:

  1. go to the AWS console (https://console.aws.amazon.com)
  2. in the top right, click on your name
  3. click on My Security Credentials
  4. click on Access keys
  5. click Create New Access Key
  6. copy your access key id and secret access key. if using aws-vault, follow the instructions there to store them. otherwise you'll need follow the instructions here to store your credentials locally

If using aws-vault, deploy with the following command:

aws-vault exec <your-profile> --no-session yarn sls deploy

The first deployment is special and requires the --no-session flag, but subsequent deploys can just be run without it:

aws-vault exec <your-profile> yarn sls deploy

Otherwise, if not using aws-vault, you can just deploy with:

yarn sls deploy

After the deployment runs successfully, it will output the endpoint that the server is reachable at, for example:

aws-vault exec ryangilbert -- yarn sls deploy
yarn run v1.22.5
$ sls deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Service files not changed. Skipping deployment...
Service Information
service: aws-node-express-api-project
stage: dev
region: us-east-1
stack: aws-node-express-api-project-dev
resources: 11
api keys:
  None
endpoints:
  ANY - https://64ymr0eu40.execute-api.us-east-1.amazonaws.com
functions:
  api: aws-node-express-api-project-dev-api
layers:
  None

Monitor Express APIs by route with the Serverless Dashboard: run "serverless"
✨  Done in 8.79s.

References

About

basic express server deployed to aws with serverless

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published