AWS API gateway reconciler
AWS API gateway reconciler checks and merges openapi schemas from services. Reconciler is cdk library construct, which could be deployed as part of AWS CDK application
npm i @affinidi/api-gw-reconciler
- Merging openapi schemas from different services in one openapi schema and updating single API gateway
- Checking for backwards compatibilty of schema
- schema path authentication for specifc service path prefix
- Pinning 1 schema to provide authorizers
- Generates and publishes json api doc
- Generates and publishes ReDoc HTML documentation
- Token Auth for documentation
For more complex example, take a look into [examples]
//Create API gw somewhere
const api = new apigateway.RestApi(this, 'api')
api.root.addMethod('ANY')
Create reconciler
//Reference apigateway in reconciler stack
const restApiId = 'fe3sdf4x'
restApiReference = apigateway.RestApi.fromRestApiId(this, 'restApiReference', restApiId)
//Create reconsiler
const reconciler = new APIGWReconciler(this, 'reconciler', {
restAPI: restApiReference
allowedAccounts: [
{
allowedApiPathPrefix: 'service1',
id: '1111111111'
},
{
allowedApiPathPrefix: 'service2',
id: '22222222222'
},
]
})
Upload openapi.json schema in service stack
const oas = {
"openapi": "3.0.0",
"paths:" : [...]
...
}
new BucketDeployment(this, 'openapiSchemaDeployment', {
destinationBucket: this.reconciler.openApiDefinitionBucket,
destinationKeyPrefix: 'service1',
prune: false,
sources: [Source.jsonData('openapi.json', oas)],
})
Take a look into detailed example
Please open an issue for support.
Please contribute using Github Flow. Create a branch, add commits, and open a pull request.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
AWS API GW reconciler.
reconciler merges openapi schemas from services and updates central API gw with result schemas
import { APIGWReconciler } from '@affinidi/api-gw-reconciler'
new APIGWReconciler(scope: Stack, id: string, props: IAPIGWReconcilerProps)
Name | Type | Description |
---|---|---|
scope |
aws-cdk-lib.Stack |
No description. |
id |
string |
No description. |
props |
IAPIGWReconcilerProps |
No description. |
- Type: aws-cdk-lib.Stack
- Type: string
- Type: IAPIGWReconcilerProps
Name | Description |
---|---|
toString |
Returns a string representation of this construct. |
public toString(): string
Returns a string representation of this construct.
Name | Description |
---|---|
isConstruct |
Checks if x is a construct. |
import { APIGWReconciler } from '@affinidi/api-gw-reconciler'
APIGWReconciler.isConstruct(x: any)
Checks if x
is a construct.
Use this method instead of instanceof
to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs
library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct
in each copy of the constructs
library
is seen as a different class, and an instance of one class will not test as
instanceof
the other class. npm install
will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof
will behave
unpredictably. It is safest to avoid using instanceof
, and using
this type-testing method instead.
- Type: any
Any object.
Name | Type | Description |
---|---|---|
node |
constructs.Node |
The tree node. |
mergedOpenapiBucket |
aws-cdk-lib.aws_s3.Bucket |
No description. |
openApiDefinitionBucket |
aws-cdk-lib.aws_s3.Bucket |
No description. |
openapiDocsLambda |
aws-cdk-lib.aws_lambda_nodejs.NodejsFunction |
No description. |
openapiInfoMetadataKey |
string |
No description. |
reconcilerLambda |
aws-cdk-lib.aws_lambda_nodejs.NodejsFunction |
No description. |
redocLambda |
aws-cdk-lib.aws_lambda_nodejs.NodejsFunction |
No description. |
public readonly node: Node;
- Type: constructs.Node
The tree node.
public readonly mergedOpenapiBucket: Bucket;
- Type: aws-cdk-lib.aws_s3.Bucket
public readonly openApiDefinitionBucket: Bucket;
- Type: aws-cdk-lib.aws_s3.Bucket
public readonly openapiDocsLambda: NodejsFunction;
- Type: aws-cdk-lib.aws_lambda_nodejs.NodejsFunction
public readonly openapiInfoMetadataKey: string;
- Type: string
public readonly reconcilerLambda: NodejsFunction;
- Type: aws-cdk-lib.aws_lambda_nodejs.NodejsFunction
public readonly redocLambda: NodejsFunction;
- Type: aws-cdk-lib.aws_lambda_nodejs.NodejsFunction
import { OpenAPIDefinitionHeader } from '@affinidi/api-gw-reconciler'
const openAPIDefinitionHeader: OpenAPIDefinitionHeader = { ... }
Name | Type | Description |
---|---|---|
info |
{[ key: string ]: any} |
No description. |
public readonly info: {[ key: string ]: any};
- Type: {[ key: string ]: any}
- Implemented By: IAPIGWReconcilerallowedAccount
aws account id to api path prefix mapping.
Name | Type | Description |
---|---|---|
allowedApiPathPrefix |
string |
API path prefix allowed for given account id . |
id |
string |
Account Id of service under API path prefix. |
public readonly allowedApiPathPrefix: string;
- Type: string
API path prefix allowed for given account id
.
public readonly id: string;
- Type: string
Account Id of service under API path prefix.
- Implemented By: IAPIGWReconcilerProps
Name | Type | Description |
---|---|---|
allowedAccounts |
IAPIGWReconcilerallowedAccount[] |
No description. |
restAPI |
aws-cdk-lib.aws_apigateway.IRestApi |
restAPI managed by reconciler. |
apiDocPathPrefix |
string |
path prefix for api doc. |
apiDocSimpleAuthToken |
string |
Simple authentication token to keep your apidoc somewhat private. |
openapiHeader |
OpenAPIDefinitionHeader |
Default schema, defines title, description, version. |
openapiInfoMetadataKey |
string |
Key in service openapi schema under info key. |
securitySchemaPath |
string |
security schema path this schema configures authorizers in API gw. |
public readonly allowedAccounts: IAPIGWReconcilerallowedAccount[];
- Type: IAPIGWReconcilerallowedAccount[]
public readonly restAPI: IRestApi;
- Type: aws-cdk-lib.aws_apigateway.IRestApi
restAPI managed by reconciler.
public readonly apiDocPathPrefix: string;
- Type: string
- Default: 'api-docs'
path prefix for api doc.
public readonly apiDocSimpleAuthToken: string;
- Type: string
- Default: ''
Simple authentication token to keep your apidoc somewhat private.
public readonly openapiHeader: OpenAPIDefinitionHeader;
- Type: OpenAPIDefinitionHeader
Default schema, defines title, description, version.
public readonly openapiInfoMetadataKey: string;
- Type: string
- Default: 'x-reconciler'
Key in service openapi schema under info key.
public readonly securitySchemaPath: string;
- Type: string
- Default: "iam/openapi.json"
security schema path this schema configures authorizers in API gw.