-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Non-Zero Exit Code is Swallowed #1081
Comments
What does your handler look like? |
Having this issue with Handler: package main
import (
"context"
"errors"
"github.com/aws/aws-lambda-go/lambda"
)
func HandleRequest(ctx context.Context, ev struct{}) (string, error) {
return "", errors.New("FAIL")
}
func main() {
lambda.Start(HandleRequest)
} $ sam --version
SAM CLI, version 0.15.0
$ git clone [email protected]:michaelgruber/aws-sam-cli-non-zero.git && cd aws-sam-cli-non-zero
$ make
$ echo "{}" | sam local invoke AWSSAMCLINonZero
2019-04-23 11:07:35 Reading invoke payload from stdin (you can also pass it from file with --event)
2019-04-23 11:07:35 Found credentials in shared credentials file: ~/.aws/credentials
2019-04-23 11:07:35 Invoking main (go1.x)
2019-04-23 11:07:35 Decompressing /Users/mgruber/Desktop/aws-sam-cli-non-zero/main.zip
Fetching lambci/lambda:go1.x Docker container image......
2019-04-23 11:07:36 Mounting /private/var/folders/6p/r4n9zccj1sl028w4_yym43g00000gn/T/tmp2majhmef as /var/task:ro,delegated inside runtime container
START RequestId: 496f2129-51a7-1e03-e917-edfaff706f09 Version: $LATEST
END RequestId: 496f2129-51a7-1e03-e917-edfaff706f09
REPORT RequestId: 496f2129-51a7-1e03-e917-edfaff706f09 Duration: 2.31 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 6 MB
{
"errorMessage": "FAIL",
"errorType": "errorString"
}
$ echo $?
0 |
There is some grey area here. The command didn't actually fail, the invoke of your function did. Currently, we treat this as a successful command (as SAM CLI didn't crash or error out). There are defiantly two views to this so marking this as needs-feedback. |
As a sidenote, with the above example, running $ echo '{}' | sam local invoke AWSSAMCLINonZero 2>err.log 1>out.log Produces an empty
With the handler changed to package main
import (
"context"
"github.com/aws/aws-lambda-go/lambda"
)
func HandleRequest(ctx context.Context, ev struct{}) (string, error) {
return `{"success":true}`, nil
}
func main() {
lambda.Start(HandleRequest)
}
If both are considered successful shouldn't the error JSON get sent to stdout? |
I'm having trouble with this same behavior in a different context. I have a python lambda that raises an error. When I deploy the lambda to AWS and use the # BoomFunction
def lambda_handler(event, context):
raise Exception('BOOM!') Remote Behaviorremote = boto3.client('lambda')
remote_res = remote.invoke(
FunctionName='BoomFunction',
InvocationType='RequestResponse',
Payload='{}'
)
remote_payload = str(remote_res['Payload'].read(), 'utf-8')
print(remote_payload)
# {"errorMessage": "BOOM!", "errorType": "Exception", "stackTrace": [" File \"/var/task/app.py\", line 37, in lambda_handler\n raise Exception('BOOM!')\n"]} Local Behaviorlocal = boto3.client('lambda', **{
'endpoint_url': 'http://127.0.0.1:3001'
})
local_res = local.invoke(
FunctionName='BoomFunction',
InvocationType='RequestResponse',
Payload='{}'
)
local_payload = str(local_res['Payload'].read(), 'utf-8')
print(local_payload)
# I do see the error message in the
|
This is also causing an issue for us when using sam local invoke in combination with other tooling. |
I was hoping to use So for now I've stitched together a fragile hack:
It's not great, but with sam 1.18 and my current nodejs-based lambda this can catch unexpected failures. Could we get something like |
Description
When a Lambda throws an error, the SAM tool prints the exception, but a zero exit code is returned.
Steps to reproduce
Create a Lambda that throws an Error.
Call the Lambda with SAM, e.g.: sam local invoke "lambda1"
Observed result
Expected result
An exit code of 1 or greater
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
--debug
The text was updated successfully, but these errors were encountered: