@stackspot/cdk-api-gateway v0.3.0
Api Gateway
Component to manage an API Gateway.
It is mandatory to add at least one integration.
How to use
Below are all languages supported by the AWS CDK.
C
Install the dependency:
dotnet add package StackSpot.Cdk.ApiGateway
Import the construct into your project, for example:
using Amazon.CDK;
using Amazon.CDK.AWS.APIGateway;
using Constructs;
using StackSpot.Cdk.ApiGateway;
namespace MyStack
{
public class MyStack : Stack
{
internal MyStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
{
EndpointType[] endpointTypes = new EndpointType[1] { EndpointType.EDGE };
new ApiGateway(this, "MyApiGateway", new ApiGatewayProps{
EndpointTypes = endpointTypes,
RestApiName = "MyRestApi"
});
}
}
}
F
Not yet supported.
Go
Not yet supported.
Java
Not yet supported.
JavaScript
Install the dependency:
npm install --save @stackspot/cdk-api-gateway
Import the construct into your project, for example:
const { Stack } = require('aws-cdk-lib');
const { EndpointType } = require('aws-cdk-lib/aws-apigateway');
const { ApiGateway } = require('@stackspot/cdk-api-gateway');
class MyStack extends Stack {
constructor(scope, id, props) {
super(scope, id, props);
new ApiGateway(this, 'MyApiGateway', {
endpointTypes: [EndpointType.EDGE],
restApiName: 'MyRestApi',
});
}
}
module.exports = { MyStack };
Python
Not yet supported.
TypeScript
Install the dependency:
npm install --save @stackspot/cdk-api-gateway
Import the construct into your project, for example:
import { Stack, StackProps } from 'aws-cdk-lib';
import { EndpointType } from 'aws-cdk-lib/aws-apigateway';
import { Construct } from 'constructs';
import { ApiGateway } from '@stackspot/cdk-api-gateway';
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
new ApiGateway(this, 'MyApiGateway', {
endpointTypes: [EndpointType.EDGE],
restApiName: 'MyRestApi',
});
}
}
Construct Props
Name | Type | Description |
---|---|---|
cors? | CorsOptions | The CORS options for the REST API. |
endpointTypes | EndpointType[] | The endpoint types of a REST API. |
policy? | string | A policy document that contains the permissions for the REST API. |
restApiDescription? | string | A description for the API Gateway RestApi resource. |
restApiName | string | A name for the API Gateway RestApi resource. |
Another Props
ApiKeyProps
Name | Type | Description |
---|---|---|
apiKeyDescription? | string | The description of the API key. |
apiKeyName | string | The name of the API key. |
KinesisDataStreamIntegrationProps
Name | Type | Description |
---|---|---|
apiKeyRequired? | boolean | Indicates whether the method requires clients to submit a valid API key. Default: true. |
iamAuthorization? | boolean | Represents whether to use IAM authentication or not. Default: false. |
kinesisArn | string | The ARN of the Kinesis for the integration. |
method | string | The method for the resource (path). |
path | string | The path for the integration. |
policy | string | The policy for the integration. |
LambdaIntegrationProps
Name | Type | Description |
---|---|---|
apiKeyRequired? | boolean | Indicates whether the method requires clients to submit a valid API key. Default: true. |
iamAuthorization? | boolean | Represents whether to use IAM authentication or not. Default: false. |
fn | IFunction | The function for the integration. |
method | string | The method for the resource (path). |
path | string | The path for the integration. |
StageProps
Name | Type | Description |
---|---|---|
clientCertificate? | boolean | The client certificate for the stage. Default: true. |
logLevel? | MethodLoggingLevel | The log level of the stage. Default: MethodLoggingLevel.ERROR. |
metricsEnabled? | boolean | Specifies whether Amazon CloudWatch metrics are enabled. Default: false. |
stageName | string | The name of the stage. |
throttlingBurstLimit? | number | Specifies the throttling burst limit. |
throttlingRateLimit? | number | Specifies the throttling rate limit. |
tracingEnabled? | boolean | Specifies whether Amazon X-Ray tracing is enabled. Default: false. |
Properties
Name | Type | Description |
---|---|---|
deployment | Deployment | The initial deployment of the REST API. |
restApi | RestApi | Represents a REST API in Amazon API Gateway. |
Methods
Name | Description |
---|---|
addApiKey(props) | Add a API key in AWS API Gateway. |
addIntegrationKinesisDataStream(props) | Add Kinesis Data Stream integration to the REST API. |
addIntegrationLambda(props) | Add Lambda integration to the REST API. |
addStage(props) | Add a stage to the REST API. |
addApiKey(props)
public addApiKey(props: ApiKeyProps): ApiKey
Parameters
- props ApiKeyProps
Returns
Add a API key in AWS API Gateway.
You can use this method to add as many API keys as you like.
addIntegrationKinesisDataStream(props)
public addIntegrationKinesisDataStream(props: KinesisDataStreamIntegrationProps)
Parameters
Add Kinesis Data Stream integration to the REST API.
addIntegrationLambda(props)
public addIntegrationLambda(props: LambdaIntegrationProps)
Paremeters
- props LambdaIntegrationProps
Add Lambda integration to the REST API.
addStage(props)
public addStage(props: StageProps): Stage
Parameters
- props StageProps
Returns
Add a stage to the REST API.
You can use this method to add as many stages as you like.
IAM Least privilege
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"apigateway:DELETE",
"apigateway:GET",
"apigateway:PATCH",
"apigateway:POST",
"apigateway:PUT",
"apigateway:UpdateRestApiPolicy",
"iam:AttachRolePolicy",
"iam:CreateRole",
"iam:DeleteRole",
"iam:DetachRolePolicy",
"iam:GetRole",
"iam:PassRole",
"ssm:GetParameters"
],
"Resource": "*"
}
]
}
Development
Prerequisites
- EditorConfig (Optional)
- Git
- Node.js 17
Setup
cd api-gateway-jsii-component
npm install