question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when setting VPC configuration in AWS Lambda Function

See original GitHub issue

Hello!

  • Vote on this issue by adding a 👍 reaction
  • To contribute a fix for this issue, leave a comment (and link to your pull request, if you’ve opened one already)

Issue details

There might be a bug when trying to associate a AWS Lambda Function with a VPC. The error is the following:

error: aws:lambda/function:Function resource 'name-of-lambda-function' has a problem: Value for unconfigurable attribute: Can't configure a value for "vpc_config.0.vpc_id": its value will be decided automatically based on the result of applying this configuration.. Examine values at 'Function.VpcConfig.VpcId'.

Steps to reproduce

The code leading to the previous message is right below:

import pulumi
import pulumi_aws as aws

default_vpc = aws.ec2.get_vpc(default=True)
default_vpc_subnets = aws.ec2.get_subnet_ids(vpc_id=default_vpc.id)
security_group_id = Config("security").require("group_id")

vpc_config = aws.lambda_.FunctionVpcConfigArgs(
  vpc_id=default_vpc.id,
  subnet_ids=default_vpc_subnets.ids,
  security_group_ids=[security_group_id],
)

trigger_prefect_flow_run_lambda = aws.lambda_.Function(
  lambda_name,
  name=lambda_name,
  code=pulumi.FileArchive("./path/to/lambda.zip"),
  role=lambda_role.arn,
  handler="app.lambda_handler",
  runtime="python3.8",
  memory_size=128,
  layers=[lambda_layer.arn],
  tags={...},
  timeout=30,  # 30 seconds
  opts=ResourceOptions(depends_on=[lambda_role_policy_attachment]),
  environment=aws.lambda_.FunctionEnvironmentArgs(
      variables={
          "VARIABLE": variable
      },
  ),
  vpc_config=vpc_config,
)

I have also tried changing vpc_id=default_vpc.id to vpc_id="vpc_XXXX" but the error persists.

Using pulumi==v3.28.0 and python 3.8.10

Expected: To associate the VPC with the AWS Lambda Function. Actual: An error raises.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
paulrobellocommented, Oct 22, 2022

It was my fault. I was importing from outputs instead of inputs. They are identical except the input marks vpcId as optional. Which makes sense.

1reaction
jkodroffcommented, Apr 12, 2022

@snikolakis This looks like a bug in the code that generates the SDK. Try not setting a value for vpc_id - just use subnet_ids.

When we fix the underlying issue, we’ll publish a new version of the provider where vpc_id is not settable, as should be the case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error when setting VPC configuration in AWS Lambda ...
The error is the following: error: aws:lambda/function:Function resource 'name-of-lambda-function' has a problem ...
Read more >
Configuring a Lambda function to access resources in a VPC
You can configure a Lambda function to connect to private subnets in a virtual private cloud (VPC) in your AWS account. Use Amazon...
Read more >
Troubleshoot timeout errors with Lambda functions in a VPC
My AWS Lambda function returns timeout errors when I configure the function to access resources in an Amazon Virtual Private Cloud (Amazon ...
Read more >
Troubleshoot networking issues in Lambda
Network connectivity errors can result from issues with your VPC's routing configuration, security group rules, AWS Identity and Access Management (IAM) role ...
Read more >
Troubleshoot connectivity issue to URI with Lambda function
You receive a connection-related error when you try to run your Amazon Virtual Private Cloud (Amazon VPC) Lambda function targeting a remote ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found