aws / aws/aws-cdk

(aws-apigatewayv2-authorizers): adding an authorizer and route to the HttpApi from another stack leads to cyclic reference

Open
#18,742 3 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-apigatewayv2-authorizers bug p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
74

Description

### What is the problem?

We have multiple stacks in our CDK setup. HttpApi is created in one stack, and routes and authorizers are created in another stacks.
However, such setup leads to cyclic reference.

### Reproduction Steps

```csharp
var app = new App();

var sharedStack = new Stack(app, "shared-stack");
var api = new HttpApi(sharedStack, "http-api");

var specificStack = new Stack(app, "specific-stack");
var authorizerLambda = new Function(specificStack, "auth-lambda", new FunctionProps
{
Runtime = Runtime.NODEJS,
Handler = "my-handler",
Code = Code.FromInline("code")
});
var authorizer = new HttpLambdaAuthorizer("api-auth", authorizerLambda, new HttpLambdaAuthorizerProps
{
ResponseTypes = new[] { HttpLambdaResponseType.SIMPLE },
ResultsCacheTtl = Duration.Minutes(10),
IdentitySource = new[] { "$request.header.X-API-Key" }
});
var route = new HttpRoute(specificStack, "http-route", new HttpRouteProps
{
HttpApi = api,
RouteKey = HttpRouteKey.With("/test", HttpMethod.GET),
Integration = new HttpUrlIntegration("integration", "https://aws.amazon.com/"),
Authorizer = authorizer
});

app.Synth();
```

### What did you expect to happen?

I need an Authorizer to be created in scope of "specific-stack", not "shared-stack".

Actually, I would expect to be able to set construct scope by myself, in construct constructor, as it happens with all the other constructs.

### What actually happened?

''shared-stack' depends on 'specific-stack' (shared-stack -> specific-stack/auth-lambda/Resource.Arn). Adding this dependency (specific-stack -> shared-stack/http-api/Resource.Ref) would create a cyclic reference.'

### CDK CLI Version

2.8.0

### Framework Version

2.8.0

### Node.js Version

v14.17.3

### OS

Windows 10

### Language

.NET

### Language Version

netcoreapp3.1

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the sample with HttpApi, HttpRoute, HttpLambdaAuthorizer, and app.Synth() across shared-stack and specific-stack. Trace the cross-stack references created by the API, route, and authorizer, and consider how construct scope is selected. Done means the authorizer remains in specific-stack and synthesis completes without a cyclic dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, csharp
Domain
api, cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.