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

[Lambda Function] subnet selection tries to evaluate subnet AZ even if AZ filtering is not specified #8301

Closed
pergardebrink opened this issue Jun 1, 2020 · 2 comments · Fixed by #9579
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud @aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort in-progress This issue is being actively worked on. needs-triage This issue or PR still needs to be triaged. p2

Comments

@pergardebrink
Copy link

pergardebrink commented Jun 1, 2020

When I try to use the Subnet.FromSubnetId method to construct a SubnetSelection, I get an error stating that I must add the availabilityZone. This does not really make any sense since I am specifying the subnet and not trying to filter anything?

Reproduction Steps

new Function(this, "function", new FunctionProps {
    // function properties... 
    VpcSubnets = new SubnetSelection {
        Subnets = new[] { Subnet.FromSubnetId(this, "Subnet", "subnet-id-I-want-to-use") }
    }
}

Error Log

Unhandled exception. Amazon.JSII.Runtime.JsiiException: You cannot reference a Subnet's availability zone if it was not supplied. Add the availabilityZone when importing using Subnet.fromSubnetAttributes()
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
   at Amazon.JSII.Runtime.Services.Client.Create(CreateRequest request)
   at Amazon.JSII.Runtime.Services.Client.Create(String fullyQualifiedName, Object[] arguments, Override[] overrides, String[] interfaces)
   at Amazon.JSII.Runtime.Deputy.DeputyBase..ctor(DeputyProps props)
   at Constructs.Construct..ctor(DeputyProps props)
   at Amazon.CDK.Construct..ctor(DeputyProps props)
   at Amazon.CDK.Resource..ctor(DeputyProps props)
   at Amazon.CDK.AWS.Lambda.FunctionBase..ctor(DeputyProps props)
   at Amazon.CDK.AWS.Lambda.Function..ctor(Construct scope, String id, IFunctionProps props)

Environment

  • CLI Version :1.42.0
  • Framework Version:
  • OS :Windows 10
  • Language :C#

Other

If I use the following code, it works, but it feels a bit ugly and hacky

new Function(this, "function", new FunctionProps {
    // function properties... 
    VpcSubnets = new SubnetSelection {
        Subnets = new[] { 
            Subnet.FromSubnetAttributes(this, "Subnet", new subnetAttributes {
                AvailabilityZone = "dummy", // This works as long as it's non-empty
                SubnetId =  "subnet-id-I-want-to-use"
            }) 
        }
    }
}

This is 🐛 Bug Report

@pergardebrink pergardebrink added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 1, 2020
@PerArneng
Copy link

    private static ISubnet getSubnetFromId(Construct scope, String id) {
        return Subnet.fromSubnetAttributes(scope, "subnet_" + id,
                  SubnetAttributes.builder()
                          .subnetId(id)
                          .availabilityZone("dummy") // https://github.com/aws/aws-cdk/issues/8301
                          .build()
        );
    } 

that code works for me as well. thanks for the workaround.

@SomayaB SomayaB added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Jun 2, 2020
@rix0rrr rix0rrr changed the title Cannot use FromSubnetId in VpcSubnets property on Function [Lambda Function] subnet selection tries to evaluate subnet AZ even if AZ filtering is not specified Jun 3, 2020
@rix0rrr rix0rrr added @aws-cdk/aws-lambda Related to AWS Lambda p2 labels Jun 3, 2020
@NetaNir NetaNir added the effort/medium Medium work item – several days of effort label Aug 10, 2020
@flemjame-at-amazon
Copy link
Contributor

This is the bare minimum code to reproduce the issue:

vpc.selectSubnets(SubnetSelection.builder()
    .subnets(Arrays.asList(
        Subnet.fromSubnetId(this, "S", "s-d135fa9b")
    ))
    .build());

@SomayaB SomayaB added the in-progress This issue is being actively worked on. label Aug 11, 2020
@mergify mergify bot closed this as completed in #9579 Aug 14, 2020
mergify bot pushed a commit that referenced this issue Aug 14, 2020
----
Closes #8301
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud @aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort in-progress This issue is being actively worked on. needs-triage This issue or PR still needs to be triaged. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants