Create API Gateway Resource
Create API Gateway Resource
- Open your CDK project and create a new stack named ApiStack. Inherit the
Stack class from the amazon.awscdk library:
public class ApiStack extends Stack {
}

- To create
ApiStack, we require the VPC, Cluster, and NetworkLoadBalancer that we previously set up. Therefore, we need to create a record class named ApiStackProps to pass into ApiStack. Add the following code outside the ApiStack class:
record ApiStackProps(
NetworkLoadBalancer networkLoadBalancer,
VpcLink vpcLink
){}

- Create the
ApiStack constructor:
public ApiStack(final Construct scope, final String id,
final StackProps props, ApiStackProps apiStackProps) {
super(scope, id, props);
}

- Initialize a
RestApi object named ECommerceAPI. This represents an API Gateway where API endpoints are declared and configured.
RestApi restApi = new RestApi(this, "RestApi",
RestApiProps.builder()
.restApiName("ECommerceAPI")
.build()
);
