@aws-cdk_aws-apigatewayv2-alpha.HttpApi

class HttpApi (construct) ๐Ÿ”น

LanguageType name
.NETAmazon.CDK.AWS.Apigatewayv2.Alpha.HttpApi
Gogithub.com/aws/aws-cdk-go/awscdkapigatewayv2alpha/v2#HttpApi
Javasoftware.amazon.awscdk.services.apigatewayv2.alpha.HttpApi
Pythonaws_cdk.aws_apigatewayv2_alpha.HttpApi
TypeScript (source)@aws-cdk/aws-apigatewayv2-alpha ยป HttpApi

Implements IConstruct, IDependable, IResource, IHttpApi, IApi

Create a new API Gateway HTTP API endpoint.

Example

import { HttpLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha';

declare const booksDefaultFn: lambda.Function;
const booksIntegration = new HttpLambdaIntegration('BooksIntegration', booksDefaultFn);

const httpApi = new apigwv2.HttpApi(this, 'HttpApi');

httpApi.addRoutes({
  path: '/books',
  methods: [ apigwv2.HttpMethod.GET ],
  integration: booksIntegration,
});

Initializer

new HttpApi(scope: Construct, id: string, props?: HttpApiProps)

Parameters

  • scope Construct
  • id string
  • props HttpApiProps

Construct Props

NameTypeDescription
apiName?๐Ÿ”นstringName for the HTTP API resource.
corsPreflight?๐Ÿ”นCorsPreflightOptionsSpecifies a CORS configuration for an API.
createDefaultStage?๐Ÿ”นbooleanWhether a default stage and deployment should be automatically created.
defaultAuthorizationScopes?๐Ÿ”นstring[]Default OIDC scopes attached to all routes in the gateway, unless explicitly configured on the route.
defaultAuthorizer?๐Ÿ”นIHttpRouteAuthorizerDefault Authorizer to applied to all routes in the gateway.
defaultDomainMapping?๐Ÿ”นDomainMappingOptionsConfigure a custom domain with the API mapping resource to the HTTP API.
defaultIntegration?๐Ÿ”นHttpRouteIntegrationAn integration that will be configured on the catch-all route ($default).
description?๐Ÿ”นstringThe description of the API.
disableExecuteApiEndpoint?๐Ÿ”นbooleanSpecifies whether clients can invoke your API using the default endpoint.

apiName?๐Ÿ”น

Type: string (optional, default: id of the HttpApi construct.)

Name for the HTTP API resource.


corsPreflight?๐Ÿ”น

Type: CorsPreflightOptions (optional, default: CORS disabled.)

Specifies a CORS configuration for an API.

See also: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html


createDefaultStage?๐Ÿ”น

Type: boolean (optional, default: true)

Whether a default stage and deployment should be automatically created.


defaultAuthorizationScopes?๐Ÿ”น

Type: string[] (optional, default: no default authorization scopes)

Default OIDC scopes attached to all routes in the gateway, unless explicitly configured on the route.


defaultAuthorizer?๐Ÿ”น

Type: IHttpRouteAuthorizer (optional, default: No authorizer)

Default Authorizer to applied to all routes in the gateway.


defaultDomainMapping?๐Ÿ”น

Type: DomainMappingOptions (optional, default: no default domain mapping configured. meaningless if createDefaultStage is false.)

Configure a custom domain with the API mapping resource to the HTTP API.


defaultIntegration?๐Ÿ”น

Type: HttpRouteIntegration (optional, default: none)

An integration that will be configured on the catch-all route ($default).


description?๐Ÿ”น

Type: string (optional, default: none)

The description of the API.


disableExecuteApiEndpoint?๐Ÿ”น

Type: boolean (optional, default: false execute-api endpoint enabled.)

Specifies whether clients can invoke your API using the default endpoint.

By default, clients can invoke your API with the default https://{api_id}.execute-api.{region}.amazonaws.com endpoint. Enable this if you would like clients to use your custom domain name.

Properties

NameTypeDescription
apiEndpoint๐Ÿ”นstringGet the default endpoint for this API.
apiId๐Ÿ”นstringThe identifier of this API Gateway API.
env๐Ÿ”นResourceEnvironmentThe environment this resource belongs to.
httpApiId๐Ÿ”นstringThe identifier of this API Gateway HTTP API.
node๐Ÿ”นNodeThe tree node.
stack๐Ÿ”นStackThe stack in which this resource is defined.
defaultStage?๐Ÿ”นIHttpStageThe default stage of this API.
disableExecuteApiEndpoint?๐Ÿ”นbooleanSpecifies whether clients can invoke this HTTP API by using the default execute-api endpoint.
httpApiName?๐Ÿ”นstringA human friendly name for this HTTP API.
url?๐Ÿ”นstringGet the URL to the default stage of this API.

apiEndpoint๐Ÿ”น

Type: string

Get the default endpoint for this API.


apiId๐Ÿ”น

Type: string

The identifier of this API Gateway API.


env๐Ÿ”น

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


httpApiId๐Ÿ”น

Type: string

The identifier of this API Gateway HTTP API.


node๐Ÿ”น

Type: Node

The tree node.


stack๐Ÿ”น

Type: Stack

The stack in which this resource is defined.


defaultStage?๐Ÿ”น

Type: IHttpStage (optional)

The default stage of this API.


disableExecuteApiEndpoint?๐Ÿ”น

Type: boolean (optional)

Specifies whether clients can invoke this HTTP API by using the default execute-api endpoint.


httpApiName?๐Ÿ”น

Type: string (optional)

A human friendly name for this HTTP API.

Note that this is different from httpApiId.


url?๐Ÿ”น

Type: string (optional)

Get the URL to the default stage of this API.

Returns undefined if createDefaultStage is unset.

Methods

NameDescription
addRoutes(options)๐Ÿ”นAdd multiple routes that uses the same configuration.
addStage(id, options)๐Ÿ”นAdd a new stage.
addVpcLink(options)๐Ÿ”นAdd a new VpcLink.
applyRemovalPolicy(policy)๐Ÿ”นApply the given removal policy to this resource.
metric(metricName, props?)๐Ÿ”นReturn the given named metric for this Api Gateway.
metricClientError(props?)๐Ÿ”นMetric for the number of client-side errors captured in a given period.
metricCount(props?)๐Ÿ”นMetric for the total number API requests in a given period.
metricDataProcessed(props?)๐Ÿ”นMetric for the amount of data processed in bytes.
metricIntegrationLatency(props?)๐Ÿ”นMetric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend.
metricLatency(props?)๐Ÿ”นThe time between when API Gateway receives a request from a client and when it returns a response to the client.
metricServerError(props?)๐Ÿ”นMetric for the number of server-side errors captured in a given period.
toString()๐Ÿ”นReturns a string representation of this construct.
static fromHttpApiAttributes(scope, id, attrs)๐Ÿ”นImport an existing HTTP API into this CDK app.

addRoutes(options)๐Ÿ”น

public addRoutes(options: AddRoutesOptions): HttpRoute[]

Parameters

  • options AddRoutesOptions

Returns

  • HttpRoute[]

Add multiple routes that uses the same configuration.

The routes all go to the same path, but for different methods.


addStage(id, options)๐Ÿ”น

public addStage(id: string, options: HttpStageOptions): HttpStage

Parameters

  • id string
  • options HttpStageOptions

Returns

  • HttpStage

Add a new stage.


addVpcLink(options)๐Ÿ”น

public addVpcLink(options: VpcLinkProps): VpcLink

Parameters

  • options VpcLinkProps

Returns

  • VpcLink

Add a new VpcLink.


applyRemovalPolicy(policy)๐Ÿ”น

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


metric(metricName, props?)๐Ÿ”น

public metric(metricName: string, props?: MetricOptions): Metric

Parameters

  • metricName string
  • props MetricOptions

Returns

  • Metric

Return the given named metric for this Api Gateway.


metricClientError(props?)๐Ÿ”น

public metricClientError(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the number of client-side errors captured in a given period.


metricCount(props?)๐Ÿ”น

public metricCount(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the total number API requests in a given period.


metricDataProcessed(props?)๐Ÿ”น

public metricDataProcessed(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the amount of data processed in bytes.


metricIntegrationLatency(props?)๐Ÿ”น

public metricIntegrationLatency(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend.


metricLatency(props?)๐Ÿ”น

public metricLatency(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

The time between when API Gateway receives a request from a client and when it returns a response to the client.

The latency includes the integration latency and other API Gateway overhead.


metricServerError(props?)๐Ÿ”น

public metricServerError(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the number of server-side errors captured in a given period.


toString()๐Ÿ”น

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromHttpApiAttributes(scope, id, attrs)๐Ÿ”น

public static fromHttpApiAttributes(scope: Construct, id: string, attrs: HttpApiAttributes): IHttpApi

Parameters

  • scope Construct
  • id string
  • attrs HttpApiAttributes

Returns

  • IHttpApi

Import an existing HTTP API into this CDK app.