A simple serverless API to list all the EC2 security groups for an account.
- 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
- You will need to provide the
Accept
header and specifyapplication/vnd.api+json
. - You don't need to worry about
Content-Type
as this is aGET
endpoint and... has no content 😛 - You will require a valid JWT, passed in as a
Bearer
token, to invoke the API - The JWT secret key will be sourced from SSM in non-local development environments
- For local development environments, the default JWT secret key will be set by
serverless.yml
. - You can generate a local JWT using jwt.io and the key in
serverless.yml
, which isCloudConformityJWTKey
. - 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
yarn install
yarn start:local
yarn test
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 |
- Irwin Razaghi [email protected]
- Github:
@irwin-r