Skip to content

irwin-r/ec2-sg-api

Repository files navigation

ec2-sg-api

Version

A simple serverless API to list all the EC2 security groups for an account.

Criteria

  • Create a Node.js ES6 module to list all EC2 security groups in an AWS Account.
  • Use this module in an AWS Lambda function.
  • Make the Lambda function available via an AWS API Gateway endpoint.
  • Make response JSON:API 1.0 compatible.
  • Wrap the Lambda, API Gateway endpoint, and utility module in a Serverless application. More info.
  • Write a unit test for your module by mocking AWS EC2 API.
  • Get a code coverage report for your test suite.
  • Secure the endpoint using a custom API Gateway Lambda Authoriser

How to invoke

  1. You will need to provide the Accept header and specify application/vnd.api+json.
  2. You don't need to worry about Content-Type as this is a GET endpoint and... has no content 😛
  3. You will require a valid JWT, passed in as a Bearer token, to invoke the API
  4. The JWT secret key will be sourced from SSM in non-local development environments
  5. For local development environments, the default JWT secret key will be set by serverless.yml.
  6. You can generate a local JWT using jwt.io and the key in serverless.yml, which isCloudConformityJWTKey.
  7. Alternatively, you can use this JWT which is only valid for the above secret key, which expires in the year 3000 😛
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImV4cCI6MzI1MDM2ODAwMDB9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.q0_5qxJnXLfTrE9rLTXbeLu-f6vBlunsNOZ0O0RubVA

Install

yarn install

Run locally

yarn start:local

Run tests

yarn test

Code Coverage

yarn coverage
File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 100 95.24 100 100
aws 100 100 100 100
index.js 100 100 100 100
handlers 100 100 100 100
authorizer.js 100 100 100 100
list.js 100 100 100 100
middlewares 100 100 100 100
errorMiddleware.js 100 100 100 100
index.js 100 100 100 100
serializers 100 100 100 100
index.js 100 100 100 100
security-group.js 100 100 100 100
utils 100 80 100 100
errors.js 100 100 100 100
validateAuthorizationToken.js 100 80 100 100 4

Author

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published