Skip to content
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

Can't set Lambda as ALB Target #17457

Closed
usman5251 opened this issue Nov 10, 2021 · 2 comments
Closed

Can't set Lambda as ALB Target #17457

usman5251 opened this issue Nov 10, 2021 · 2 comments
Assignees
Labels
@aws-cdk/aws-elasticloadbalancingv2-targets bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@usman5251
Copy link

usman5251 commented Nov 10, 2021

What is the problem?

Previously I was able to use the below stack to set Lambda Function as ALB target. Now it doesn't work

# VPC
vpc = ec2.Vpc(self, "MyVpc",
    max_azs=3,
)

# ALB
load_balancer = elbv2.ApplicationLoadBalancer(self, "LB",
    idle_timeout=core.Duration.seconds(180),
    vpc=vpc,
    internet_facing=True,
)



# ALB listening PORT
listener = load_balancer.add_listener("Listener",
    port=80,
    open=True,
)

# ALB Target
listener.add_targets("Targets",
    targets=[targets.LambdaTarget(Lambda_function)],
)

Now I get this error:

***** |  7/46 | 3:51:01 PM | CREATE_FAILED        | AWS::ElasticLoadBalancingV2::TargetGroup  | LB/Listener/TargetsGroup (LBListenerTargetsGroup76EF81E8) The provided target group attribute is not supported (Service: AmazonElasticLoadBalancing; Status Code: 400; Error Code: InvalidConfigurationRequest; Request ID: e31d9925-38b0-4c5d-8a20-e0035004d33f; Proxy: null)
	new TargetGroupBase (/tmp/jsii-kernel-NDU3Bi/node_modules/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.js:44:25)
	\_ new ApplicationTargetGroup (/tmp/jsii-kernel-NDU3Bi/node_modules/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-target-group.js:26:9)
	\_ ApplicationListener.addTargets (/tmp/jsii-kernel-NDU3Bi/node_modules/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.js:228:23)
	\_ /tmp/tmpmiwjswxa/lib/program.js:8248:134
	\_ Kernel._wrapSandboxCode (/tmp/tmpmiwjswxa/lib/program.js:8860:24)
	\_ /tmp/tmpmiwjswxa/lib/program.js:8248:107
	\_ Kernel._ensureSync (/tmp/tmpmiwjswxa/lib/program.js:8841:28)
	\_ Kernel.invoke (/tmp/tmpmiwjswxa/lib/program.js:8248:34)
	\_ KernelHost.processRequest (/tmp/tmpmiwjswxa/lib/program.js:9757:36)
	\_ KernelHost.run (/tmp/tmpmiwjswxa/lib/program.js:9720:22)
	\_ Immediate._onImmediate (/tmp/tmpmiwjswxa/lib/program.js:9721:46)
	\_ processImmediate (internal/timers.js:464:21)

I was able to use a workaround and I think I know what the problem is, Please read Other Information

Reproduction Steps

This stack should be enough to reproduce error:

# VPC
vpc = ec2.Vpc(self, "MyVpc",
    max_azs=3,
)

# ALB
load_balancer = elbv2.ApplicationLoadBalancer(self, "LB",
    idle_timeout=core.Duration.seconds(180),
    vpc=vpc,
    internet_facing=True,
)



# ALB listening PORT
listener = load_balancer.add_listener("Listener",
    port=80,
    open=True,
)

# ALB Target
listener.add_targets("Targets",
    targets=[targets.LambdaTarget(Lambda_function)],
)

What did you expect to happen?

Creation of ALB with Lambda as its target.

What actually happened?

I get this error:

***** |  7/46 | 3:51:01 PM | CREATE_FAILED        | AWS::ElasticLoadBalancingV2::TargetGroup  | LB/Listener/TargetsGroup (LBListenerTargetsGroup76EF81E8) The provided target group attribute is not supported (Service: AmazonElasticLoadBalancing; Status Code: 400; Error Code: InvalidConfigurationRequest; Request ID: e31d9925-38b0-4c5d-8a20-e0035004d33f; Proxy: null)
	new TargetGroupBase (/tmp/jsii-kernel-NDU3Bi/node_modules/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.js:44:25)
	\_ new ApplicationTargetGroup (/tmp/jsii-kernel-NDU3Bi/node_modules/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-target-group.js:26:9)
	\_ ApplicationListener.addTargets (/tmp/jsii-kernel-NDU3Bi/node_modules/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.js:228:23)
	\_ /tmp/tmpmiwjswxa/lib/program.js:8248:134
	\_ Kernel._wrapSandboxCode (/tmp/tmpmiwjswxa/lib/program.js:8860:24)
	\_ /tmp/tmpmiwjswxa/lib/program.js:8248:107
	\_ Kernel._ensureSync (/tmp/tmpmiwjswxa/lib/program.js:8841:28)
	\_ Kernel.invoke (/tmp/tmpmiwjswxa/lib/program.js:8248:34)
	\_ KernelHost.processRequest (/tmp/tmpmiwjswxa/lib/program.js:9757:36)
	\_ KernelHost.run (/tmp/tmpmiwjswxa/lib/program.js:9720:22)
	\_ Immediate._onImmediate (/tmp/tmpmiwjswxa/lib/program.js:9721:46)
	\_ processImmediate (internal/timers.js:464:21)

CDK CLI Version

1.132.0 (build 5c75891)

Framework Version

No response

Node.js Version

v16.11.0

OS

Manjaro

Language

Python

Language Version

Python 3.6

Other information

I had another project that used the same stack, Which used to work without any problems, Luckily I had the project with its Python Virtual Environment. I pip freeze > requirements.txt on that environment and used that requirements.txt in the current project. All went well then

Working Requirements.txt:

attrs==20.3.0
aws-cdk.assets==1.109.0
aws-cdk.aws-apigateway==1.109.0
aws-cdk.aws-applicationautoscaling==1.109.0
aws-cdk.aws-autoscaling==1.109.0
aws-cdk.aws-autoscaling-common==1.109.0
aws-cdk.aws-autoscaling-hooktargets==1.109.0
aws-cdk.aws-certificatemanager==1.109.0
aws-cdk.aws-cloudformation==1.109.0
aws-cdk.aws-cloudfront==1.109.0
aws-cdk.aws-cloudwatch==1.109.0
aws-cdk.aws-codebuild==1.109.0
aws-cdk.aws-codecommit==1.109.0
aws-cdk.aws-codeguruprofiler==1.109.0
aws-cdk.aws-codepipeline==1.109.0
aws-cdk.aws-codestarnotifications==1.109.0
aws-cdk.aws-cognito==1.109.0
aws-cdk.aws-dynamodb==1.109.0
aws-cdk.aws-ec2==1.109.0
aws-cdk.aws-ecr==1.109.0
aws-cdk.aws-ecr-assets==1.109.0
aws-cdk.aws-ecs==1.109.0
aws-cdk.aws-ecs-patterns==1.109.0
aws-cdk.aws-efs==1.109.0
aws-cdk.aws-elasticloadbalancing==1.109.0
aws-cdk.aws-elasticloadbalancingv2==1.109.0
aws-cdk.aws-elasticloadbalancingv2-targets==1.109.0
aws-cdk.aws-events==1.109.0
aws-cdk.aws-events-targets==1.109.0
aws-cdk.aws-globalaccelerator==1.109.0
aws-cdk.aws-iam==1.109.0
aws-cdk.aws-kinesis==1.109.0
aws-cdk.aws-kinesisfirehose==1.109.0
aws-cdk.aws-kms==1.109.0
aws-cdk.aws-lambda==1.109.0
aws-cdk.aws-logs==1.109.0
aws-cdk.aws-route53==1.109.0
aws-cdk.aws-route53-targets==1.109.0
aws-cdk.aws-s3==1.109.0
aws-cdk.aws-s3-assets==1.109.0
aws-cdk.aws-sam==1.109.0
aws-cdk.aws-secretsmanager==1.109.0
aws-cdk.aws-servicediscovery==1.109.0
aws-cdk.aws-signer==1.109.0
aws-cdk.aws-sns==1.109.0
aws-cdk.aws-sns-subscriptions==1.109.0
aws-cdk.aws-sqs==1.109.0
aws-cdk.aws-ssm==1.109.0
aws-cdk.aws-stepfunctions==1.109.0
aws-cdk.cloud-assembly-schema==1.109.0
aws-cdk.core==1.109.0
aws-cdk.custom-resources==1.109.0
aws-cdk.cx-api==1.109.0
aws-cdk.region-info==1.109.0
boto3==1.17.102
botocore==1.20.102
cattrs==1.0.0
certifi==2021.5.30
chardet==4.0.0
constructs==3.3.87
idna==2.10
importlib-resources==5.1.4
install==1.3.4
jmespath==0.10.0
jsii==1.30.0
publication==0.0.3
python-dateutil==2.8.1
requests==2.25.1
requests-toolbelt==0.9.1
s3transfer==0.4.2
selenium==3.141.0
six==1.16.0
typing-extensions==3.10.0.0
urllib3==1.26.5
zipp==3.4.1

Not working requirements.txt:

aws_cdk.core
aws_cdk.aws_events_targets
aws_cdk.aws_lambda
aws_cdk.aws_apigateway
aws_cdk.aws_elasticloadbalancingv2_targets
aws-cdk.aws_ec2
requests~=2.26.0
xmltodict~=0.12.0

I also found another issue, which I think is root cause of the issue. On running cdk synth, there is one major difference in output

output of cdk synth using latest dependencies (NOT WORKING):

....
LBListenerTargetsGroup76EF81E8:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      TargetGroupAttributes:
        - Key: stickiness.enabled
          Value: "false"
      Targets:
        - Id:
            Fn::GetAtt:
              - ********8D1D94D0
              - Arn
      TargetType: lambda
    DependsOn:
....

output of cdk synth using old dependencies:

....
LBListenerTargetsGroup76EF81E8:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Targets:
        - Id:
            Fn::GetAtt:
              - ********8D1D94D0
              - Arn
      TargetType: lambda
    DependsOn:
....

Notice NOT WORKING cdk synth output has TargetGroupAttributes, while WORKING cdk synth output don't.

Please let me know if something is not clear.

@usman5251 usman5251 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 10, 2021
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Nov 10, 2021
@ryparker ryparker added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Nov 10, 2021
blacha added a commit to linz/basemaps that referenced this issue Nov 11, 2021
kodiakhq bot added a commit to linz/basemaps that referenced this issue Nov 11, 2021
…fixed (#1962)

See aws/aws-cdk#17457

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@nija-at nija-at removed their assignment Nov 24, 2021
@nija-at nija-at added @aws-cdk/aws-elasticloadbalancingv2-targets needs-triage This issue or PR still needs to be triaged. and removed @aws-cdk/aws-lambda Related to AWS Lambda p1 effort/small Small work item – less than a day of effort labels Nov 24, 2021
@njlynch
Copy link
Contributor

njlynch commented Nov 24, 2021

Duplicate of #17261

@njlynch njlynch marked this as a duplicate of #17261 Nov 24, 2021
@njlynch njlynch closed this as completed Nov 24, 2021
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-elasticloadbalancingv2-targets bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants