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

Make invocation URL dynamic and fix default function name #46

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

skwashd
Copy link

@skwashd skwashd commented Sep 4, 2021

Issue #, if available:

Description of changes:

The API endpoint in Amazon's implementation of Lambda used the path /2015-03-31/functions/[func]/invocations to invoke the function. [func] the name of the function and is set as the value of the AWS_LAMBDA_FUNCTION_NAME environment variable when the function is executing on AWS.

The emulator uses a hard coded endpoint of /2015-03-31/functions/function/invocations. This is even the case
when the AWS_LAMBDA_FUNCTION_NAME environment variable is set to another value.

This patch changes the endpoint URL when the AWS_LAMBDA_FUNCTION_NAME environment variable is set. In this case the invocation URL will be /2015-03-31/functions/${AWS_LAMBDA_FUNCTION_NAME}/invocations. When the environment variable isn't set, the current behaviour persists and the function name is set to function.

The end result is the emulator behaviour is closer to the real environment the functions execute in.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

skwashd added a commit to skwashd/aws-lambda-runtime-interface-emulator that referenced this pull request Sep 4, 2021
As noted in aws#46, the function name is derived from
the URL used to invoke it. The emulator uses `function`
in the API endpoint, but the `AWS_LAMBDA_FUNCTION_NAME`
environment variable is set to `test_function`. This
is an inconsistency between the emulator and the AWS
environment.
@skwashd skwashd mentioned this pull request Sep 4, 2021
Copy link
Contributor

@valerena valerena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good, but there are conflicts in the test cases (we renamed the file and added testing capabilities for multiple architectures). If you bring those changes and fix the tests, we should be good to go.

@skwashd
Copy link
Author

skwashd commented Oct 4, 2021

@valerena thanks. Fixed, but before merging this you should review my comment on #49 (comment).

skwashd added a commit to skwashd/aws-lambda-runtime-interface-emulator that referenced this pull request Oct 5, 2021
As noted in aws#46, the function name is derived from
the URL used to invoke it. The emulator uses `function`
in the API endpoint, but the `AWS_LAMBDA_FUNCTION_NAME`
environment variable is set to `test_function`. This
is an inconsistency between the emulator and the AWS
environment.
@valerena valerena changed the title Make invocation URL dynamic Make invocation URL dynamic and fix default function name Oct 19, 2021
@valerena valerena self-requested a review October 19, 2021 16:04
@skwashd
Copy link
Author

skwashd commented Nov 2, 2021

@valerena bumping the thread as suggested in #49 (comment)

@valerena
Copy link
Contributor

valerena commented Nov 3, 2021

Hi @skwashd , we had a discussion with the team and there are concerns about backwards compatibility and breaking existing customers that had automated local calls for testing using RIE. The consensus is that this behavior could be optional, having to pass an extra parameter to have it like this.

To have this as the default behavior might come in the future, but it's something that we still have to confirm with more stakeholders and if it happens it could take several months, to make sure that we have all use cases covered and the right communication about that change.

I know that this has already taken more time than what I imagined you originally expected, but if you change this Pull Request to work as an optional behavior I would work to prioritize its revision and include it in a shorter amount of time that what has taken to review the rest of the changes so far.
Let me know if this sounds okay for you.

@skwashd
Copy link
Author

skwashd commented Nov 3, 2021

@valerena it's always "fun" trying to fix broken behaviour when people rely on the (broken) behaviour 😢

Before I spend more time on this, I'd like to make sure we're aligned on the details.

Is the proposal to keep the default function name fix as implemented in ebc933d as is? I hope this is a less controversial change as the default function name should match the path in the url. I hope many users aren't depending on the AWS_LAMBDA_FUNCTION_NAME environment variable being set to test_function.

For the invoke URL change, I propose that if AWS_LAMBDA_FUNCTION_NAME is set, we have the server listen on both the hardcoded function path and the one generated from the environment variable. It will use the same handler function for both. If the variable isn't set, we simply listen on the function path.

This approach keeps backwards compatibility and makes it easier to remove the broken behaviour down the road. I will ensure I minimise any duplicated logic. Does this work for you and the team? I'd like to see the old hardcoded function path url when the variable is set marked as deprecated in the docs, or is that too soon?

@valerena
Copy link
Contributor

valerena commented Nov 3, 2021

@skwashd The team's stance on this is that RIE wasn't launched to be an exact copy of Lambda's Control Plane, so the current behavior is not "broken", and it's just "the way that RIE works". So, we shouldn't make any changes to the "default behavior", even if we think not many people use that. Every change that could break existing customers should be activated through a specific flag passed, and we won't change the recommended path url for now, even if the other url is also available.

It's possible than during next year we will have a longer discussion about the future here and potentially add your recommendations as the default behavior, but at this moment we don't have the resources to start that conversation.

As noted in aws#46, the function name is derived from
the URL used to invoke it. The emulator uses `function`
in the API endpoint, but the `AWS_LAMBDA_FUNCTION_NAME`
environment variable is set to `test_function`. This
is an inconsistency between the emulator and the AWS
environment.
The API endpoint in Amazon's implementation of Lambda used the path
`/2015-03-31/functions/[func]/invocations` to invoke the function.
`[func]` the name of the function and is set as the value of the
`AWS_LAMBDA_FUNCTION_NAME` environment variable when the function
is executing on AWS.

The emulator uses a hard coded endpoint of
`/2015-03-31/functions/function/invocations`. This is even the case
when the `AWS_LAMBDA_FUNCTION_NAME` environment variable is set to
another value.

This patch changes the endpoint URL when the `AWS_LAMBDA_FUNCTION_NAME`
environment variable is set. In this case the invocation URL will
be `/2015-03-31/functions/${AWS_LAMBDA_FUNCTION_NAME}/invocations`.
When the environment variable isn't set, the current behaviour
persists and the function name is set to `function`.

The end result is the emulator behaviour is closer to the real
environment the functions execute in.

This PR fixes aws#43 I raised a few weeks ago.
@skwashd
Copy link
Author

skwashd commented Dec 28, 2021

@valerena lets agree to disagree on inconsistent behaviour is a bug or a feature. I've incorporated the discussions we've discussed here. All the existing tests pass and I added tests to exercise the new functionality.

gregtyler added a commit to ministryofjustice/opg-s3-antivirus that referenced this pull request Mar 3, 2022
Use alpine as a base image, and install clamav properly so that it's just available on PATH. This led to a few changes to how we call `clamscan` and `freshclam`.

Without lambci, we now need `aws-lambda-rie` to provide the Lambda runtime environment (i.e. the HTTP API). Because this is just needed for local dev, mount it rather than installing on the image directly.

`aws-lambda-rie` causes two restrictions:
- The function name must be "function". There's [a PR to make this configurable](aws/aws-lambda-runtime-interface-emulator#46), but AWS don't seem keen
- It can only handle one invokation at a time, so we can't upload the second test file (and therefore invoke the Lamdba) until the first is finished

#minor
gregtyler added a commit to ministryofjustice/opg-s3-antivirus that referenced this pull request Mar 3, 2022
Use alpine as a base image, and install clamav properly so that it's just available on PATH. This led to a few changes to how we call `clamscan` and `freshclam`.

Without lambci, we now need `aws-lambda-rie` to provide the Lambda runtime environment (i.e. the HTTP API). Because this is just needed for local dev, mount it rather than installing on the image directly.

`aws-lambda-rie` causes two restrictions:
- The function name must be "function". There's [a PR to make this configurable](aws/aws-lambda-runtime-interface-emulator#46), but AWS don't seem keen
- It can only handle one invokation at a time, so we can't upload the second test file (and therefore invoke the Lamdba) until the first is finished

#minor
@skwashd
Copy link
Author

skwashd commented Mar 29, 2022

@valerena any update on this one?

@swantzter
Copy link

Hi, @valerena any updates on this? We're running into issues due to not being able to change the function name when trying to invoke the function from AWS step functions local this is making it hard for us to develop and run test locally

@valerena
Copy link
Contributor

Hi. I'm really sorry this is taking so long. Our team is very very short on resources, and at the moment we only have this package in maintenance mode, only upgrading the version of Go because of security related findings.

The change overall looks good, but we don't have the bandwidth to review it thoroughly, merge it, release it, and monitor in the future if this causes any unintended consequences that would cause us to have to revert it back.

I can't promise any dates, but I can tell that we won't be able to take this during June either, but we'll see during July how are things by then and potentially have bandwidth to take a deeper look.

I'm sorry this is affecting your flows. Maybe you can compile the binary with these changes and use it manually instead of using the official version for now as a workaround (if that works for your use case), and I hope we can get enough resourcing in July to dedicate more time to this repository.

@swantzter
Copy link

Hi @valerena, just wanted to check in on this and see if there's any potential for progress, but given the commit history I assume the situation for your team hasn't gotten to a better state yet?

@skwashd
Copy link
Author

skwashd commented Dec 31, 2022

@valerena Can I please get an update on this?

@cppntn
Copy link

cppntn commented Mar 2, 2023

Can you guys finally merge this please?

@timini
Copy link

timini commented Mar 23, 2023

hit the button, merge it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants