-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws-elasticloadbalancingv2: cannot create lambda TargetGroup #17261
Comments
For reproduction, run diff --git a/bin/cdk-issue.ts b/bin/cdk-issue.ts
index eb0c70e..fa0d52c 100644
--- a/bin/cdk-issue.ts
+++ b/bin/cdk-issue.ts
@@ -11,7 +11,7 @@ new CdkIssueStack(app, 'CdkIssueStack', {
/* Uncomment the next line to specialize this stack for the AWS Account
* and Region that are implied by the current CLI configuration. */
- // env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
+ env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
/* Uncomment the next line if you know exactly what Account and Region you
* want to deploy the stack to. */
diff --git a/lib/cdk-issue-stack.lambda.ts b/lib/cdk-issue-stack.lambda.ts
new file mode 100644
index 0000000..46a7acb
--- /dev/null
+++ b/lib/cdk-issue-stack.lambda.ts
@@ -0,0 +1,5 @@
+export async function handler(
+ event: any,
+): Promise<any> {
+ return {};
+}
\ No newline at end of file
diff --git a/lib/cdk-issue-stack.ts b/lib/cdk-issue-stack.ts
index aa6e79e..864ac2e 100644
--- a/lib/cdk-issue-stack.ts
+++ b/lib/cdk-issue-stack.ts
@@ -1,9 +1,24 @@
import * as cdk from '@aws-cdk/core';
+import * as ec2 from '@aws-cdk/aws-ec2';
+import * as lb from '@aws-cdk/aws-elasticloadbalancingv2';
+import * as targets from '@aws-cdk/aws-elasticloadbalancingv2-targets';
+import * as lambda from '@aws-cdk/aws-lambda-nodejs';
export class CdkIssueStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
- // The code that defines your stack goes here
+ const alb = new lb.ApplicationLoadBalancer(this, 'lb', {
+ vpc: ec2.Vpc.fromLookup(this, 'vpc', { isDefault: true }),
+ });
+ const listener = alb.addListener('Listener', {
+ port: 80
+ });
+ listener.addTargets('Target', {
+ port: 80,
+ targets: [
+ new targets.LambdaTarget(new lambda.NodejsFunction(this, 'lambda')),
+ ],
+ });
}
}
diff --git a/package.json b/package.json
index 236f05f..cc6e0e4 100644
--- a/package.json
+++ b/package.json
@@ -14,13 +14,18 @@
"@aws-cdk/assert": "1.130.0",
"@types/jest": "^26.0.10",
"@types/node": "10.17.27",
+ "aws-cdk": "1.130.0",
"jest": "^26.4.2",
"ts-jest": "^26.2.0",
- "aws-cdk": "1.130.0",
"ts-node": "^9.0.0",
"typescript": "~3.9.7"
},
"dependencies": {
+ "@aws-cdk/aws-ec2": "^1.130.0",
+ "@aws-cdk/aws-elasticloadbalancingv2": "^1.130.0",
+ "@aws-cdk/aws-elasticloadbalancingv2-targets": "^1.130.0",
+ "@aws-cdk/aws-lambda-nodejs": "^1.130.0",
"@aws-cdk/core": "1.130.0",
"source-map-support": "^0.5.16"
} |
I can confirm this issue. Had to pin "1.129.0" to keep CDK avoiding this bug. The issue seems to be related with #17111. |
Temporary workaround: const defaultTargetGroupFunc = new lambda.Function(this, 'DefaultTargetGroupFunc', {
runtime: lambda.Runtime.NODEJS_12_X,
handler: 'index.handler',
code: lambda.Code.fromInline(
'exports.handler = async function (event, context) {console.log(JSON.stringify(event));}'
),
logRetention: logs.RetentionDays.ONE_WEEK,
})
const defaultFuncPermission = new lambda.CfnPermission(this, 'perm', {
action: 'lambda:InvokeFunction',
functionName: defaultTargetGroupFunc.functionName,
principal: 'elasticloadbalancing.amazonaws.com',
})
const lambdaTarget = new elbv2Targets.LambdaTarget(defaultTargetGroupFunc)
const defaultTargetGroup = new alb.ApplicationTargetGroup(this, 'DefaultTargetGroup', {
targetType: alb.TargetType.LAMBDA,
targets: [lambdaTarget],
})
const cfnDefaultTargetGroup = defaultTargetGroup.node.defaultChild as alb.CfnTargetGroup
cfnDefaultTargetGroup.addDependsOn(defaultFuncPermission)
// TODO: remove this once https://github.com/aws/aws-cdk/issues/17261 is fixed
cfnDefaultTargetGroup.addDeletionOverride('Properties.TargetGroupAttributes') |
Thanks all for clearly describing the issue and providing a workaround, much appreciated 😄 I can confirm the behavior described here |
Facing similar issue in python. Can anyone provide temporary fix for python also? That will be really appreciated. Thank you |
Got it after trying few things. Following is snippet of what I did.
In the above code tg1 is object of elbv2.ApplicationTargetGroup. |
Any idea when this issue will be fixed? There have been 2 releases of the CDK since it was introduced and it's still present... |
Also affected by this 😨 |
Much simple workaround - 'listener.addTargets(...).setAttribute('stickiness.enabled', undefined)' |
imo this is great cause its an easy half-a-line fix and outlines exactly which properties are problematic with a direct fix 👍 |
#17271 seems to be ready to be merged and included in next release. Any update on this? |
|
A target group with HTTPS protocol does not support the attribute stickiness.enabled adding the exact error text so this thread is more easily searched from google |
What is the problem?
Cannot create lambda TargetGroup as the created cfn template has
stickiness.enabled
set as true in TargetGroupAttributes. Seems like this attribute is not expected for lambda based target groups.Reproduction Steps
const lambdaTargetGroup = new ApplicationTargetGroup(this,
TargetGroup
, {targets: [new targets.LambdaTarget(lambdaFunction)],
});
You should be able to see
stickiness.enabled
set in cfn template. During deployment , deployment fails withThe provided target group attribute is not supported (Service: AmazonElasticLoadBalancing; Status Code: 400
What did you expect to happen?
Target group with lambda targets getting created successfully
What actually happened?
Target group with lambda targets are not getting created
CDK CLI Version
1.130
Framework Version
No response
Node.js Version
17.0.1
OS
macos 11.3.1
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: