skip to Main Content

I’m not sure and struggling to fetch Integration property ‘Integration ID’ of HTTP API Gateway. Below is the code (in C#) to create an Integration, however, since ‘Integration ID’ is not available, I’m not able to attach it to the ‘Route’ using CDK.

var cfnIntegration = new CfnIntegration(this, "Intergration", new CfnIntegrationProps()
{
   ApiId = cfnAPI.AttrApiId,
   IntegrationType = "AWS_PROXY",
   IntegrationUri = "arn:aws:lambda:us-east-1:123456789:function:TestFunction",
   IntegrationMethod = "POST",
   PayloadFormatVersion = "2.0",
});

The above code creates Integration, successfully, but not yet attached to the Route, shown below:

CfnRoute cfnRoute = new CfnRoute(this, "Routes", new CfnRouteProps()
{
  ApiId = cfnAPI.AttrApiId,
  RouteKey = "POST /webhook/digitalChannel,
  Target = $"integrations/{integration_id}" // <--- This is where the problem is, can't attach the above created Integration since integration_id is not known
});

enter image description here

2

Answers


  1. Target = $"integrations/{cfnIntegration.Ref}" 
    

    A L1 construct’s Ref property will be rendered at synth-time as a CloudFormation Ref intrinsic function. At deploy-time, as the AWS::ApiGatewayV2::Integration CloudFormation docs say, "Ref returns the Integration resource ID, such as abcd123".

    Login or Signup to reply.
  2. The integration ID is the return value from the CloudFormation resource.
    You can use CFN intrinsic functions to reference it (or access the Ref member on the CDK resource).

    Additionally, string interpolation is not useable in this case because the value is only resolved during deployment. You’ll have to use the Join intrinsic function to get around this.

    I’m not all that familiar with C# but it should look something like the following:

    CfnRoute cfnRoute = new CfnRoute(this, "Routes", new CfnRouteProps()
    {
      ApiId = cfnAPI.AttrApiId,
      RouteKey = "POST /webhook/digitalChannel",
      Target = Fn.Join("/", {"integrations", cfnIntegration.Ref})
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search