Add option for a lambda function URL for testing#17
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
=======================================
Coverage 98.28% 98.28%
=======================================
Files 10 10
Lines 408 408
=======================================
Hits 401 401
Misses 7 7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This pull request adds an optional Lambda Function URL feature to the scheduled-lambda module to enable on-demand testing without waiting for scheduled execution. The implementation introduces a new create_test_url variable that conditionally creates an unauthenticated, publicly accessible Lambda Function URL for testing purposes.
Changes:
- Added
create_test_urlboolean variable with defaultfalseto control Function URL creation - Created AWS Lambda Function URL resource and associated permissions when enabled
- Exposed the Function URL through module outputs for easy access
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| modules/scheduled-lambda/variables.tf | Added create_test_url boolean variable to control test URL creation |
| modules/scheduled-lambda/outputs.tf | Added test_function_url output to expose the generated URL when enabled |
| modules/scheduled-lambda/main.tf | Implemented Lambda Function URL resource and two permission resources (conditionally created) |
| examples/basic/variables.tf | Propagated create_test_url variable to example configuration |
| examples/basic/main.tf | Passed through create_test_url to module and exposed output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| resource "aws_lambda_permission" "allow_function_url" { | ||
| count = var.create_test_url ? 1 : 0 | ||
| statement_id = "AllowFunctionUrlInvoke" | ||
| action = "lambda:InvokeFunctionUrl" | ||
| function_name = aws_lambda_function.scheduled.function_name | ||
| principal = "*" | ||
| function_url_auth_type = "NONE" | ||
| } | ||
|
|
||
| resource "aws_lambda_permission" "allow_function_url_invoke" { | ||
| count = var.create_test_url ? 1 : 0 | ||
| statement_id = "AllowFunctionUrlInvokeFunction" | ||
| action = "lambda:InvokeFunction" | ||
| function_name = aws_lambda_function.scheduled.function_name | ||
| principal = "*" | ||
| } |
There was a problem hiding this comment.
These two lambda permission resources appear to be redundant. When creating a Lambda Function URL with authorization_type = "NONE", only one aws_lambda_permission resource with action = "lambda:InvokeFunction" is needed. The "lambda:InvokeFunctionUrl" action and "function_url_auth_type" parameter in the first resource are not standard AWS Terraform provider parameters. Consider removing the first permission resource (allow_function_url) and keeping only the second one (allow_function_url_invoke), as it follows the correct pattern seen in the EventBridge permission at line 115.
There was a problem hiding this comment.
To invoke a function URL, you must have lambda:InvokeFunctionUrl and lambda:InvokeFunction permissions. Found this out the hard way with some 403s.
| resource "aws_lambda_function_url" "test" { | ||
| count = var.create_test_url ? 1 : 0 | ||
| function_name = aws_lambda_function.scheduled.function_name | ||
| authorization_type = "NONE" | ||
| } | ||
|
|
||
| resource "aws_lambda_permission" "allow_function_url" { | ||
| count = var.create_test_url ? 1 : 0 | ||
| statement_id = "AllowFunctionUrlInvoke" | ||
| action = "lambda:InvokeFunctionUrl" | ||
| function_name = aws_lambda_function.scheduled.function_name | ||
| principal = "*" | ||
| function_url_auth_type = "NONE" | ||
| } |
There was a problem hiding this comment.
The aws_lambda_function_url is configured with authorization_type = "NONE" and the corresponding aws_lambda_permission for lambda:InvokeFunctionUrl uses principal = "*", which makes this Lambda function URL publicly invokable over the internet with no authentication. Anyone who discovers the URL can trigger the function, potentially leading to data exfiltration, unintended side effects, or abuse if this module is used in a non-test or production environment. Consider requiring authenticated access (e.g., AWS_IAM) or at minimum documenting and enforcing that this resource can only be enabled in tightly controlled, non-production environments (for example via environment-specific variables or additional guards).
There was a problem hiding this comment.
Added more clear warning about risks in README and variable description (7dc95d1)
| resource "aws_lambda_permission" "allow_function_url_invoke" { | ||
| count = var.create_test_url ? 1 : 0 | ||
| statement_id = "AllowFunctionUrlInvokeFunction" | ||
| action = "lambda:InvokeFunction" | ||
| function_name = aws_lambda_function.scheduled.function_name | ||
| principal = "*" | ||
| } | ||
|
|
There was a problem hiding this comment.
The aws_lambda_permission resource allow_function_url_invoke grants lambda:InvokeFunction with principal = "*", which allows any AWS account to invoke this Lambda directly via the AWS API if they know its ARN. This creates a broad cross-account access exposure that goes beyond the unauthenticated function URL and could be abused for unauthorized invocation or lateral movement in multi-account setups. Restrict this permission to the specific AWS service or account that needs to invoke the function (or remove it entirely if it is not required for the function URL path).
| resource "aws_lambda_permission" "allow_function_url_invoke" { | |
| count = var.create_test_url ? 1 : 0 | |
| statement_id = "AllowFunctionUrlInvokeFunction" | |
| action = "lambda:InvokeFunction" | |
| function_name = aws_lambda_function.scheduled.function_name | |
| principal = "*" | |
| } |
There was a problem hiding this comment.
Added more clear warning about risks in README and variable description (7dc95d1)
|
@ethanholz This should be ready for review. I might improve docs on the URL variable to emphasize that it isn't recommended for long-lived deployments. This should be a pretty easy review. |
ethanholz
left a comment
There was a problem hiding this comment.
All of this looks great, merging.
Waiting for the scheduled job to kick off in order to do an E2E test is a hassle. This gives an option to add a test URL, so I can trigger the lambda it with a quick
curl.No auth, so not recommended for production, but very convenient for a quick test.