-
Notifications
You must be signed in to change notification settings - Fork 2
Compatibility w/ AWS Fargate #1
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
base: develop
Are you sure you want to change the base?
Conversation
Merge changes for v1.2 release
Merge changes for v1.3 release
Merge changes for v1.8 release
Merge changes for v1.9 release
Merge changes for v1.11 release
README.md
Outdated
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.
Update readme:
- Set
AWS_LAMBDA_SERVER_MAX_INVOCATIONS
to 1 to exit server after one invocation API_ACCESS_KEY
is token used to access apiforward-response
is header to forward response to
bin/aws-lambda-rie
Outdated
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.
Binary built files
bin/lambda-entrypoint.sh
Outdated
# Set API_ACCESS_KEY if api_access_key exists | ||
if [ -f "${LAMBDA_TASK_ROOT}/.api_access_key" ]; then | ||
export API_ACCESS_KEY=$(cat ${LAMBDA_TASK_ROOT}/.api_access_key) | ||
rm -f ${LAMBDA_TASK_ROOT}/.api_access_key | ||
fi |
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.
lambda-entrypoint.sh
is called as the ENTRYPOINT, which is executed when the image is started.
Added this section, where it reads the .api_access_key
file into the API_ACCESS_KEY
environment variable. Then removes the file
// Fix CORS error: https://github.com/aws/aws-lambda-runtime-interface-emulator/pull/84/files#diff-2c1a36d379bd5ed6e893749912ac8473cc46dddf5765024d46b44da2eb56348d | ||
if origin := r.Header.Get("Origin"); origin != "" { | ||
w.Header().Set("Access-Control-Allow-Origin", GetenvWithDefault("ACCESS_CONTROL_ALLOW_ORIGIN", origin)) | ||
w.Header().Set("Access-Control-Allow-Methods", GetenvWithDefault("ACCESS_CONTROL_ALLOW_METHODS", "POST, OPTIONS")) | ||
w.Header().Set("Access-Control-Allow-Headers", GetenvWithDefault("ACCESS_CONTROL_ALLOW_HEADERS", "*")) | ||
w.Header().Set("Access-Control-Allow-Credentials", GetenvWithDefault("ACCESS_CONTROL_ALLOW_CREDENTIALS", "true")) | ||
} | ||
if r.Method == "OPTIONS" { | ||
w.WriteHeader(200) | ||
return | ||
} |
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.
Fixes CORS error, allows all origin
time.Sleep(100 * time.Millisecond) | ||
//initDone = false | ||
doneCallback(invokeResp) // Call done after printEndReports |
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.
At the end, call doneCallback
maxInvocations := -1 // -1 means unlimited invocations | ||
// Get max invocations from environment variable | ||
maxInvocationsStr := os.Getenv("AWS_LAMBDA_SERVER_MAX_INVOCATIONS") | ||
if maxInvocationsStr != "" { | ||
if maxInvocationsInt, err := strconv.Atoi(maxInvocationsStr); err == nil { | ||
maxInvocations = maxInvocationsInt | ||
} else { | ||
log.Panicf("Invalid value for AWS_LAMBDA_SERVER_MAX_INVOCATIONS: %s", maxInvocationsStr) | ||
} | ||
} |
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.
Read the AWS_LAMBDA_SERVER_MAX_INVOCATIONS
environment variable into the maxInvocations
variable.
} | ||
|
||
// Channel to signal server shutdown | ||
shutdownChan := make(chan struct{}) |
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.
Golang uses these channels to block code until the shutdownChan
is triggered
// Pass a channel | ||
http.HandleFunc("/2015-03-31/functions/function/invocations", func(w http.ResponseWriter, r *http.Request) { | ||
InvokeHandler(w, r, sandbox.LambdaInvokeAPI(), bs) | ||
InvokeHandler(w, r, sandbox.LambdaInvokeAPI(), bs, func(invokeResp *ResponseWriterProxy){ |
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.
This function is called at the end of the response
|
||
// Create an API request to the URL in the "forward-response" header | ||
client := &http.Client{} | ||
req, err := http.NewRequest("POST", forwardURL, bytes.NewReader(apiPayloadJSON)) |
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.
if forward-response
exists in the headers, send a POST request to the URL at the forward-response
maxInvocations-- | ||
if maxInvocations == 0 { | ||
close(shutdownChan) | ||
} |
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.
Decrement the maxInvocations, if ==0, then shut down the server
go func() { | ||
<-shutdownChan | ||
log.Printf("Maximum invocations (%s) reached. Shutting down the server", maxInvocationsStr) | ||
if err := srv.Shutdown(nil); err != nil { | ||
log.Panic(err) | ||
} | ||
}() |
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.
if shutdownChan
is closed, then srv.Shutdown(nil)
is called to shut down the server
@PointlessUser please review |
There was a problem hiding this comment.
Ch F438 oose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
No description provided.