AWS Simplify CodeGen
Based on openapi-codegen
Node.js-based codegen for OpenAPI documents. This project was initially by tailoring from openapi-codegen to use the core code generation functionality to generate the lambda based node projects and AWS CloudFormation stack.
npm install -g aws-simplify@latest
aws-simplify create -i spec.yaml -o ../output
Purpose to have one solution in a microservices stack with:
- AWS API Gateway REST API
- AWS Secret Manager
- AWS Lambda function 1
- AWS Lambda function 2
- AWS Secret Manager
From your existing spec.yaml, an OpenAPI specs, add extra definitions:
x-api-gateway-name
: to define the API gateway Rest API stack namex-api-service-name
: to define lambda function name that host the codex-api-service-model-name
: to redirect the related routing paths into a service group
openapi: 3.0.0info: version: 0.0.1 title: microservices-stack-namex-api-gateway-name: api-gateway-restapi-namex-deployment-name: microservice-demox-deployment-region: eu-central-1x-deployment-profile: your-aws-profilex-api-hystrix-dashboard: falsepaths: '/path-to-key': x-event-service-name: api-service-for-pets x-event-service-listen-from: path-to-s3-bucket-name put: x-event-service-model-code-plain-text: - module.exports.handle = function(event) { ', event) } x-event-service-model-access: Action: - logs:PutLogEvents Resource: - arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*:log-stream:* description: 'Run on event operation' responses: '200': description: Success '/pets': x-api-service-name: api-service-for-pets x-api-service-tag: devel get: x-api-service-model-list-objects: aws-s3 x-api-service-model-list-objects-from: path-to-s3-bucket-name/path-to-key tags: - Pets Service Group description: 'Get Pets Information' operationId: getPets parameters: - name: cats in: query schema: type: string required: false responses: '200': description: Success post: x-api-service-model-create-object: aws-s3 x-api-service-model-create-object-name: path-to-s3-bucket-name/path-to-key x-api-service-model-create-object-data: dataObject tags: - Pets Service Group description: 'Create Pets Information' operationId: createPet requestBody: description: Optional description in *Markdown* required: true content: application/json: schema: type: object properties: dataObject: type: object responses: '200': description: Success put: x-api-service-model-update-object: aws-s3 x-api-service-model-update-object-name: path-to-s3-bucket-name/path-to-key x-api-service-model-update-object-data: dataObject x-api-service-model-update-object-fields: ['foo', 'test'] tags: - Pets Service Group description: 'Update Pets Information' operationId: updatePetWithFields requestBody: description: Optional description in *Markdown* required: true content: application/json: schema: type: object properties: dataObject: type: object responses: '200': description: Success '/pets/{id}': x-api-service-name: api-service-for-pets x-api-service-model-name: people-pets x-api-service-hystrix-stream: true post: x-control-service-circuit-protection: true x-control-service-circuit-timeout: 60000 x-control-service-circuit-duration: 30000 x-control-service-circuit-threshold: 0.1 tags: - Pets Service Group description: 'Create Pets Information By Id' operationId: linkPetToPerson parameters: - in: path name: id required: true schema: type: string - in: query name: filter schema: type: string requestBody: description: Optional description in *Markdown* required: true content: application/json: schema: type: object properties: foo: type: string responses: '200': description: Success '/people': x-api-service-name: api-service-for-people x-api-service-model-name: people-pets get: x-api-service-model-get-object: aws-s3 x-api-service-model-get-object-name: path-to-s3-bucket-name/path-to-key x-api-service-model-get-object-fields: ['foo', 'test'] tags: - People Service Group description: 'Get People Information' operationId: getPeople responses: '200': description: Success put: tags: - People Service Group description: 'Update People Information' operationId: putPeople responses: '200': description: Success post: tags: - People Service Group description: 'Create People Information By Id' operationId: createPeople responses: '200': description: Successservers: - url: /
Generate project code by using command line:
aws-simplify create -i spec.yaml -o ../output/microservices