Cannot find HttpApi construct in CDK v2

I'm trying to add an HttpApi to my project that already uses CDK v2. I'm able to retrieve the HttpApi class from @aws-cdk/aws-apigatewayv2:

https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-apigatewayv2.HttpApi.html

But I'm not able to retrieve the construct in the new v2 aws-cdk-lib module:

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2-readme.html

Has the package been moved in v2?

Also, what is the difference between HttpApi and this https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sam.CfnHttpApi.html?

Thanks :)


Solution 1:

The L2 HttpApi construct is in @aws-cdk/aws-apigatewayv2-alpha. In CDK V2, experimental modules are published in separate "alpha" packages.

CfnHttpApi is the L1 construct that represents the CloudFormation AWS::ApiGatewayV2::Api resource. Under the hood, HttpApi has a CfnHttpApi as a child node. Cfn-prefixed constructs are published in aws-cdk-lib because they are stable.

Solution 2:

New location of HttpApi construct

From migrating to AWS CDK V2:

Experimental constructs are provided in separate, independently-versioned packages with names that end in alpha and an alpha version number that corresponds to the first release of aws-cdk-lib with which they are compatible.

Since the HttpApi construct is considered experimental, it has been moved to a separate package:

Link to construct page

Link to overview of new experimental package labelled alpha

Difference between CfnHttpApi, CfnApi and HttpApi

CfnHttpApi documentation (Not experimental)

CfnApi documentation (Not experimental)

HttpApi documentation (Experimental)

CfnHttpApi and CfnApi are L1 constructs, which means they directly convert to a single CloudFormation resource block. HttpApi is a L2 construct, which are usually more complex and can convert to one or more CloudFormation resource blocks. This CDK Developer guide page on Constructs provides more details on how L1 and L2 constructs work.

CfnHttpApi and CfnApi are both CloudFormation resource types which create HTTP APIs, but CfnHttpApi is the AWS SAM version of CfnApi. Quoting this page, AWS SAM templates are an extension of AWS CloudFormation templates, with some additional components that make them easier to work with.