class HttpApi (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.Apigatewayv2.HttpApi |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsapigatewayv2#HttpApi |
![]() | software.amazon.awscdk.services.apigatewayv2.HttpApi |
![]() | aws_cdk.aws_apigatewayv2.HttpApi |
![]() | aws-cdk-lib » aws_apigatewayv2 » HttpApi |
Implements
IConstruct
, IDependable
, IResource
, IHttp
, IApi
Create a new API Gateway HTTP API endpoint.
Example
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
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
Http
Api Props
Construct Props
Name | Type | Description |
---|---|---|
api | string | Name for the HTTP API resource. |
cors | Cors | Specifies a CORS configuration for an API. |
create | boolean | Whether a default stage and deployment should be automatically created. |
default | string[] | Default OIDC scopes attached to all routes in the gateway, unless explicitly configured on the route. |
default | IHttp | Default Authorizer applied to all routes in the gateway. |
default | Domain | Configure a custom domain with the API mapping resource to the HTTP API. |
default | Http | An integration that will be configured on the catch-all route ($default). |
description? | string | The description of the API. |
disable | boolean | Specifies whether clients can invoke your API using the default endpoint. |
route | boolean | Whether to set the default route selection expression for the API. |
apiName?
Type:
string
(optional, default: id of the HttpApi construct.)
Name for the HTTP API resource.
corsPreflight?
Type:
Cors
(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.
The scopes are used with a COGNITO_USER_POOLS authorizer to authorize the method invocation.
defaultAuthorizer?
Type:
IHttp
(optional, default: no default authorizer)
Default Authorizer applied to all routes in the gateway.
defaultDomainMapping?
Type:
Domain
(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:
Http
(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. Set this to
true if you would like clients to use your custom domain name.
routeSelectionExpression?
Type:
boolean
(optional, default: false)
Whether to set the default route selection expression for the API.
When enabled, "${request.method} ${request.path}" is set as the default route selection expression.
Properties
Name | Type | Description |
---|---|---|
api | string | Get the default endpoint for this API. |
api | string | The identifier of this API Gateway API. |
env | Resource | The environment this resource belongs to. |
http | string | The identifier of the HTTP API. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
default | string[] | Default OIDC scopes attached to all routes in the gateway, unless explicitly configured on the route. |
default | IHttp | Default Authorizer applied to all routes in the gateway. |
default | IHttp | The default stage of this API. |
disable | boolean | Specifies whether clients can invoke this HTTP API by using the default execute-api endpoint. |
http | string | A human friendly name for this HTTP API. |
url? | string | Get 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:
Resource
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 the HTTP API.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
defaultAuthorizationScopes?
Type:
string[]
(optional)
Default OIDC scopes attached to all routes in the gateway, unless explicitly configured on the route.
The scopes are used with a COGNITO_USER_POOLS authorizer to authorize the method invocation.
defaultAuthorizer?
Type:
IHttp
(optional)
Default Authorizer applied to all routes in the gateway.
defaultStage?
Type:
IHttp
(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
Name | Description |
---|---|
add | Add multiple routes that uses the same configuration. |
add | Add a new stage. |
add | Add a new VpcLink. |
apply | Apply the given removal policy to this resource. |
arn | Get the "execute-api" ARN. |
metric(metricName, props?) | Return the given named metric for this Api Gateway. |
metric | Metric for the number of client-side errors captured in a given period. |
metric | Metric for the total number API requests in a given period. |
metric | Metric for the amount of data processed in bytes. |
metric | Metric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend. |
metric | The time between when API Gateway receives a request from a client and when it returns a response to the client. |
metric | Metric for the number of server-side errors captured in a given period. |
to | Returns a string representation of this construct. |
static from | Import an existing HTTP API into this CDK app. |
addRoutes(options)
public addRoutes(options: AddRoutesOptions): HttpRoute[]
Parameters
- options
Add
Routes Options
Returns
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
Http
Stage Options
Returns
Add a new stage.
addVpcLink(options)
public addVpcLink(options: VpcLinkProps): VpcLink
Parameters
- options
Vpc
Link Props
Returns
Add a new VpcLink.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
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
).
arnForExecuteApi(method?, path?, stage?)
public arnForExecuteApi(method?: string, path?: string, stage?: string): string
Parameters
- method
string
- path
string
- stage
string
Returns
string
Get the "execute-api" ARN.
When 'ANY' is passed to the method, an ARN with the method set to '*' is obtained.
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
- props
Metric
Options
Returns
Return the given named metric for this Api Gateway.
metricClientError(props?)
public metricClientError(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the number of client-side errors captured in a given period.
metricCount(props?)
public metricCount(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the total number API requests in a given period.
metricDataProcessed(props?)
public metricDataProcessed(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the amount of data processed in bytes.
metricIntegrationLatency(props?)
public metricIntegrationLatency(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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
Http
Api Attributes
Returns
Import an existing HTTP API into this CDK app.