-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add function to invoke a lambda using an invocation type of "DryRun" #817
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I'm a little worried about a sprawling collection of InvokeXXX
functions for every permutation: e.g., one for dry run, one not dry run, one async, one not, etc. Perhaps the new thing to add is an InvokeFunctionWithParams
function that lets you pass in the settings, such as InvocationType
, in a struct
?
I would have taken that approach, but your comment to my issue said: "PR to add this, perhaps in a new function, is welcome!" The "new function" suggested you didn't want what you are now suggesting. I can do it the other way ... I just want to make sure which way you truly want it done. |
I should also point out that there are only three invocation types. Adding |
|
My apologies for the misunderstanding. I am confused so I want to make sure we're on the same page before I modify any more code. And more apologies if I repeat what you already know ... You're suggesting a new function
I initially assumed the enhancement request would involve a boolean argument to Terratest's So to be clear, when you suggest the creation of an Regarding your concern about multiple flavors of Also, I see the "DryRun" invocation as a pass/fail sort of function. It doesn't actually invoke the function; it just tests that it has permissions to do so. So, it kind of does it's own thing. When support for an an "Event" invocation is handled, that's a bit more complicated and you might end up splitting that out as well. Just my two cents. |
Yup, this is an annoying limitation of Go.
Not quite. It's a new function that accepts a new |
I've added the function you requested and updated the gist with the test results. When handling different invocation types, you have to be prepared for different types of output, so I needed a struct for the output (e.g., "DryRun" has no payload and the status is in the returned structure). Here's the signature for the new function:
LambdaOptions and LambdaOutput are subsets of lambda.InvokeInput and lambda.InvokeOutput, respectively. Note: this actually is an "E" function; I didn't create a non-E and E function, but I'm not sure it makes sense to have a non-E version. |
Provides a more general solution for other types of Lambda invocations.
- Restore InvokeFunction so it once again calls InvokeFunctionE version InvokeFunctionWithParams - Use functionName as an argument and not a field of the LambdaOptions struct.
Restore original InvokeFunctionE().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just a couple tweaks and then I can run tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! I'll kick off tests now.
Tests passed. Merging now. |
Provides the functionality to invoke a Lambda with an InvocationType of "DryRun". This functionality provides a simple verification of a Lambda's installation.
This functionality was implemented through the new function
InvokeDryRunE()
, which returns a status code and an error. I debated about the return values, but a status code and error seemed consistent with the return values from the AWS SDK. When the the AWS SDKInvoke()
is called with a invocation type of DryRun,StatusCode
is the only field in the returnedInvokeOutput
struct that has a value, even when there is an error. AStatusCode
value of 204 indicates the DryRun was successful and further details are then found in the returned error:I also debated whether there was a value to creating a
InvokeDryRun()
(no "E" at the end) version of the function to simply return the status code and no error. I assumed if the dry run failed, the error was needed, soInvokeDryRun()
wouldn't have much utility.And I debated adding a test of an error condition. The dry run can determine whether the user or role has permission to execute the Lambda, which would be more involved to set up. I could specify a bad function name, but that's not really the point of a dry run invocation.
This pull request is a bit of a trial balloon to determine just what you'd like to see for this added functionality.
Issue: #802
Test results: https://gist.github.com/kbalk/fbb68f156d391eacf4d330b7870e1401