0.3.0 • Published 2 years ago

@stackspot/cdk-api-gateway v0.3.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Api Gateway

aws-cdk jsii npm-version nuget-version npm-downloads nuget-downloads license

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

NameTypeDescription
cors?CorsOptionsThe CORS options for the REST API.
endpointTypesEndpointType[]The endpoint types of a REST API.
policy?stringA policy document that contains the permissions for the REST API.
restApiDescription?stringA description for the API Gateway RestApi resource.
restApiNamestringA name for the API Gateway RestApi resource.

Another Props

ApiKeyProps

NameTypeDescription
apiKeyDescription?stringThe description of the API key.
apiKeyNamestringThe name of the API key.

KinesisDataStreamIntegrationProps

NameTypeDescription
apiKeyRequired?booleanIndicates whether the method requires clients to submit a valid API key. Default: true.
iamAuthorization?booleanRepresents whether to use IAM authentication or not. Default: false.
kinesisArnstringThe ARN of the Kinesis for the integration.
methodstringThe method for the resource (path).
pathstringThe path for the integration.
policystringThe policy for the integration.

LambdaIntegrationProps

NameTypeDescription
apiKeyRequired?booleanIndicates whether the method requires clients to submit a valid API key. Default: true.
iamAuthorization?booleanRepresents whether to use IAM authentication or not. Default: false.
fnIFunctionThe function for the integration.
methodstringThe method for the resource (path).
pathstringThe path for the integration.

StageProps

NameTypeDescription
clientCertificate?booleanThe client certificate for the stage. Default: true.
logLevel?MethodLoggingLevelThe log level of the stage. Default: MethodLoggingLevel.ERROR.
metricsEnabled?booleanSpecifies whether Amazon CloudWatch metrics are enabled. Default: false.
stageNamestringThe name of the stage.
throttlingBurstLimit?numberSpecifies the throttling burst limit.
throttlingRateLimit?numberSpecifies the throttling rate limit.
tracingEnabled?booleanSpecifies whether Amazon X-Ray tracing is enabled. Default: false.

Properties

NameTypeDescription
deploymentDeploymentThe initial deployment of the REST API.
restApiRestApiRepresents a REST API in Amazon API Gateway.

Methods

NameDescription
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

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

Add Lambda integration to the REST API.

addStage(props)

public addStage(props: StageProps): Stage

Parameters

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

Setup

cd api-gateway-jsii-component
npm install