https://github.com/1Strategy/serverless-ci-cd
Serverless demo using Code Build and CodePipeline for CI/CD
https://github.com/1Strategy/serverless-ci-cd
Last synced: 11 months ago
JSON representation
Serverless demo using Code Build and CodePipeline for CI/CD
- Host: GitHub
- URL: https://github.com/1Strategy/serverless-ci-cd
- Owner: 1Strategy
- License: apache-2.0
- Created: 2017-12-14T21:29:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T17:25:19.000Z (about 3 years ago)
- Last Synced: 2024-11-29T08:39:25.045Z (over 1 year ago)
- Language: JavaScript
- Size: 405 KB
- Stars: 22
- Watchers: 6
- Forks: 14
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Serverless CI/CD Tutorial
## Building, testing, and deploying Serverless apps using CodeBuild and CodePipeline
This repo is the demo code for a [three-part tutorial](http://www.1strategy.com/blog/) on managing unit testing, integration testing, and deployment of apps built using the Serverless framework.
To play with this code locally, clone this repo and do the following:
### 1. Install global npm modules
```
npm install -g serverless eslint jest
```
### 2. Install local npm modules
Navigate to the app directory, and run
```
npm install
```
### 3. Bring up the DB
```
sls dynamodb install --stage dev
sls dynamodb start --stage dev
sls dynamodb migrate --stage dev
```
This series of commands installs a local DynamoDB, starts it, and creates any tables specified in the `serverless.yml`. Check your shell at [http://localhost:8000/shell/](http://localhost:8000/shell/) to interact with the db and view the created table.
### 4. Start the offline app
```
sls offline start --stage dev
```
The app is now available at `http://localhost:3000`.
The app has two endpoints:
#### GET /todos
Returns a list of todos:
```
[
{
"id": "9b3c415f-ceaa-49e3-b5af-0e335bfd4635",
"completed": false,
"title": "do things!",
"updatedAt": 1513817875660
}
]
```
#### POST /todos
Accepts an object in this format:
```
{
"title": "do things!",
"completed": false
}
```
Returns a status of 200. The created object is not returned; you can see it with a GET /todos.
### 5. Run Tests
To run unit tests, use
```
npm test
```
To lint, use
```
npm run-script lint
```
To run integration tests, use
```
npm run-script integration
```
### 6. Make Changes
If you change the `serverless.yml` file, you'll need to restart your local app:
- Stop the offline app; `ctrl-c` in the terminal where it's running is all you need. It's fine to leave the db running.
- Uncomment the line in the `serverless.yml` file that says `noStart: true`. This will prevent serverless offline from trying to start a new database.
- Run `sls offline start --stage dev` again.
Changes to any other file in the app (e.g. a handler) will be reflected immediately, and don't require a restart.