Create API Gateway Resource

Create API Gateway Resource

  1. 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 {
       
   }

Architect

  1. 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
   ){}

Architect

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

Architect

  1. 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()
                );

Architect