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回答
0
承認された回答

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
エキスパート
回答済み 10ヶ月前
  • 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
回答済み 10ヶ月前
  • 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

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ