XT-i / aws-lambda-jenkins-plugin

Jenkins plugin for AWS Lambda deployment
MIT License
39 stars 41 forks source link

lambda invoked successfully but fails jenkins build with JSON error #94

Open d-rep opened 6 years ago

d-rep commented 6 years ago

After a successful lambda deploy + invoke, I was seeing a jenkins job fail with the following error.

Also:   hudson.remoting.ProxyException: net.sf.json.JSONException: Invalid JSON String
hudson.remoting.ProxyException: net.sf.json.JSONException: Invalid JSON String
    at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:143)
    at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:103)
    at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:84)
    at de.taimos.pipeline.aws.utils.JsonUtils.fromString(JsonUtils.java:33)
    at de.taimos.pipeline.aws.InvokeLambdaStep$Execution.run(InvokeLambdaStep.java:153)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:50)
    at hudson.security.ACL.impersonate(ACL.java:290)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

My configuration is like this:

withAWS(credentials:'jenkins') {
  awsIdentity()
  invokeLambda([
    awsRegion: region,
    awsAccessKeyId: env.AWS_ACCESS_KEY_ID,
    awsSecretKey: env.AWS_SECRET_ACCESS_KEY,
    functionName: lambda.name,
    payload: '{}',
    synchronous: false, // Shouldn't this ignore the response?
  ])
}

The lambda being invoked was python where the last line was return 'Finished'. The fix was to change that to simply return without a string.

I think I am getting "Invalid JSON String" when the response was'Finished' because string literals can't be parsed, but AWS allows it as a valid return. Should this fail the whole job?

It would also be friendlier if the error from invokeLambda mentioned that the response was the culprit. I mistakenly thought it was the input payload or jsonParameters that were the problem.

In addition, why does response even matter when I have synchronous: false ?

vincentclee commented 4 years ago

Using returnValueAsString: true on the upstream works as well.

String result = invokeLambda(
    functionName: 'myLambdaFunction',
    payloadAsString: '{"key": "value"}',
    returnValueAsString: true
)

https://github.com/jenkinsci/pipeline-aws-plugin#invokelambda

Introduced in 1.17 https://github.com/jenkinsci/pipeline-aws-plugin#117-use--118