Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ivkos/vcs-stratus


https://github.com/ivkos/vcs-stratus

Last synced: 4 days ago
JSON representation

Awesome Lists containing this project

README

        

# vcs-stratus

This is VCS Stratus service SAM template.

## Requirements

* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/installing.html)
* [NodeJS 8.10+ installed](https://nodejs.org/en/download/)
* [Docker installed](https://www.docker.com/community-edition)

## Setup process

### Installing dependencies

In this example we use `npm` but you can use `yarn` if you prefer to manage NodeJS dependencies:

```bash
cd src
npm install
cd ../
```

### Local development

**Invoking function locally through local API Gateway**

```bash
sam local start-api
```

If the previous command ran successfully you should now be able to hit the following local endpoint to invoke your function `http://localhost:3000/`

**SAM CLI** is used to emulate both Lambda and API Gateway locally and uses our `template.yaml` to understand how to bootstrap this environment (runtime, where the source code is, etc.) - The following excerpt is what the CLI will read in order to initialize an API and its routes:

```yaml
...
Events:
ProxyApiRoot:
Type: Api
Properties:
Path: /
Method: any
ProxyApiGreedy:
Type: Api
Properties:
Path: /{proxy+}
Method: any
```

## Packaging and deployment

AWS Lambda NodeJS runtime requires a flat folder with all dependencies including the application. SAM will use `CodeUri` property to know where to look up for both application and dependencies:

```yaml
...
StratusFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
...
```

Next, the following command will create a Cloudformation Stack and deploy your SAM resources.

```bash
sam deploy \
--template-file serverless-output.yaml \
--stack-name vcs-stratus-stack \
--capabilities CAPABILITY_IAM \
--parameter-overrides Param1=paramvalue Param2=paramvalue
```

> **See [Serverless Application Model (SAM) HOWTO Guide](https://github.com/awslabs/serverless-application-model/blob/master/HOWTO.md) for more details in how to get started.**

After deployment is complete you can run the following command to retrieve the API Gateway Endpoint URL:

```bash
aws cloudformation describe-stacks \
--stack-name vcs-stratus-stack \
--query 'Stacks[].Outputs'
```

## Testing

We use `mocha` for testing our code and it is already added in `package.json` under `scripts`, so that we can simply run the following command to run our tests:

```bash
cd src
npm test
```

## AWS CLI commands

AWS CLI commands to package, deploy and describe outputs defined within the cloudformation stack:

```bash
sam package \
--template-file template.yaml \
--output-template-file packaged.yaml \
--s3-bucket REPLACE_THIS_WITH_YOUR_S3_BUCKET_NAME

sam deploy \
--template-file packaged.yaml \
--stack-name vcs-stratus-stack \
--capabilities CAPABILITY_IAM \
--parameter-overrides MyParameterSample=MySampleValue
```

**NOTE**: Alternatively this could be part of package.json scripts section.