CDK API gateway integration with VPC Link.

0

Hi, I have an API that I want to integrate with VPC link. In the aws document, we have found MockIntegration, LambdaIntegration, AwsIntegration and HttpIntegration. I don't see the VPC link integration. I have all the required parameters. Is there any way to integrate VPC link? Please suggest with your valuable information. Thanks. CDK VPC Link integration

2 Answers
0
Accepted Answer

Have you tried the official document, or is something missing there? https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.VpcLink.html

profile picture
EXPERT
answered 10 months ago
  • This doc is mentioning IntegrationType as HTTP_PROXY, but in our case looking for IntegrationType as VpCLink

0

To integrate an API with a VPC Link using the AWS CDK (Cloud Development Kit), you can use the AwsIntegration class. The AwsIntegration class allows you to configure an integration with various AWS services, including VPC Links. Here's an example of how you can integrate your API with a VPC Link using CDK:

import * as cdk from 'aws-cdk-lib';
import { RestApi, AwsIntegration } from 'aws-cdk-lib/aws-apigateway';
import { VpcLink } from 'aws-cdk-lib/aws-apigatewayv2';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyStack');

// Create the VPC Link
const vpcLink = new VpcLink(stack, 'MyVpcLink', {
  targets: [/* Specify your VPC endpoints or NLBs here */],
});

// Create the API Gateway RestApi
const api = new RestApi(stack, 'MyApi');

// Create the integration with the VPC Link
const integration = new AwsIntegration({
  service: 'your-service', // Replace with the service name you want to integrate with
  vpcLink,
});

// Create a resource and add a method with the VPC Link integration
const resource = api.root.addResource('my-resource');
resource.addMethod('GET', integration);

app.synth();

In the above code, you create a VPC Link using the VpcLink class, specifying the targets (such as VPC endpoints or NLBs) that you want to integrate with. Then, you create the API Gateway RestApi and the AwsIntegration with the desired service name and the VPC Link. Finally, you create a resource and add a method to the resource with the VPC Link integration.

Make sure to replace 'your-service' with the actual service name you want to integrate with (e.g., 's3' for Amazon S3).

This example demonstrates how to integrate a VPC Link with an API using the AWS CDK. Ensure that you have the necessary dependencies installed and adapt the code to your specific use case and CDK setup.

Dan
answered 10 months ago
  • Is there any option to add Endpoint Url? In the attached photo you can see this option Endpoint Url. How I can add this?

  • above code will not work as vpcLink is not a property of AwsIntegrationProps

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions