aws-lambda-jenkins-plugin icon indicating copy to clipboard operation
aws-lambda-jenkins-plugin copied to clipboard

lambda invoked successfully but fails jenkins build with JSON error

Open d-rep opened this issue 7 years ago • 1 comments

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 ?

d-rep avatar Oct 17 '18 19:10 d-rep

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

vincentclee avatar Feb 03 '20 18:02 vincentclee