-
-
Notifications
You must be signed in to change notification settings - Fork 794
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
go-runner implementation #1320
go-runner implementation #1320
Conversation
const sts = new AWS.STS() | ||
|
||
const { Credentials } = await sts | ||
.getSessionToken({ | ||
DurationSeconds: MIN_ALLOWED_SESSION_DURATION_S, // 900-inf | ||
}) | ||
.promise() |
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.
Uncertain about this, but credentials are not passed into go without setting them in env.
const out = handlerCode.replace( | ||
'"github.com/aws/aws-lambda-go/lambda"', | ||
'lambda "github.com/icarus-sullivan/mock-lambda"', | ||
) |
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.
Clone code and swap out lambda import, mock-lambda looks for the LAMBDA_EVENT
and LAMBDA_CONTEXT
and tries to process it.
) | ||
} | ||
|
||
const cp = spawnSync(`go`, ['run', cwdPath], { |
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.
Pros vs Cons of calling the handler like this:
Pros:
- Always gets the latest code, you can modify the handler and rerun it and voila newest changes
- It is less invasive in respect to copying and pre-compiling code elsewhere to be called
Cons:
- It is somewhat slow as it compiles before it is run
... I'm sure there are more, this is just some ideas
@medikoo What do I need to get this peer reviewed? What metrics should I be shooting for? |
eb738ba
to
c6581e8
Compare
IS_LAMBDA_AUTHORIZER: | ||
event.type === 'REQUEST' || event.type === 'TOKEN', | ||
IS_LAMBDA_REQUEST_AUTHORIZER: event.type === 'REQUEST', | ||
IS_LAMBDA_TOKEN_AUTHORIZER: event.type === 'TOKEN', |
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.
Added initial support for custom authorizers
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.
Thank you @icarus-sullivan, that looks great. There's just one file that I believe was committed in by mistake, please remove it and we should be good
yarn.lock
Outdated
@@ -0,0 +1,9593 @@ | |||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. |
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.
Let's not add this file
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.
Sounds good, I removed the file in the PR. Glad to contribute :D
c6581e8
to
b37743d
Compare
} | ||
|
||
// Clean up after we created the temporary file | ||
this.cleanup() |
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.
I put this in to aggressively cleanup tmp files, but as a side-effect it might wipe sts session info on each call. One could argue that it is a good thing to only retain session credentials to the lambda invocation, but it might slowdown subsequent requests when obtaining new sessions. As a security concern I think it should be left in imo, but I'm open to changing it.
) | ||
|
||
try { | ||
mkdirSync(this.#tmpPath, { recursive: true }) |
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.
Let's use just async functions (and async/await syntax)
b37743d
to
0cb9256
Compare
} | ||
|
||
// Make sure we have the mock-lambda runner | ||
sync('go', ['get', 'github.com/icarus-sullivan/mock-lambda@e065469']) |
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.
Constructors aren't created in an async manner, so using sync here only.
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.
Thank you @icarus-sullivan !
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.
@icarus-sullivan unfortunately CI crashes, there must be some issues, please check the errors
@medikoo Saw that, tried to reproduce yesterday in some test pipelines. Still debugging but might be slow, just giving a status update. |
@medikoo Found the issue, it's related to the sts call in the pipeline. Going to try to use the aws config env variable and see if that helps. Again, might be a while - its been a busy week. |
01401e9
to
a2d14a3
Compare
@medikoo Okay, think I resolved the issue. Whenever you are ready to run the 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.
Thank you @icarus-sullivan !
Great to see this. I noticed that this is rather incompatible with the way the serverless template generates its code. When the serverless template generates its code, the yaml file points to bin files/built go lang files. It would be worth having something in the readme IMO. |
@icarus-sullivan Just recently, I was looking for an alternative to So, I thought I'd try this one. If I can make it so that it executes the binary file specified in the handler of serverless.yaml (or serverless.ts), it will behave as I expect. |
The runner copies the path and code outlined in the handler and generates a main.go file. So it should be referencing the handler path correctly but generating a mock lambda runner on-the-fly. Let me know if that makes sense. |
Thank you for confirming and sorry for the late reply.
I checked and the handler path seems to point to the project root(same directory as serverless.ts).
From this, I am assuming that the following configuration is expected.
However, in my project, I am developing the following configuration.
Therefore, I want to run the handler(in this case, bin/go-binary) configured in serverless.ts when started with serverless-offline. |
Description
Clumsily added Go support for offline lambdas.
Motivation and Context
Why is this change required
Adding a new supported runtime isn't a requirement.
What problem does is solve?
Allows someone to run go lambdas offline.
How Has This Been Tested?
Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
macOS Catalina
vs. 10.15.4