Skip to content
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

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

Open
d-rep opened this issue Oct 17, 2018 · 1 comment
Open

Comments

@d-rep
Copy link

d-rep commented Oct 17, 2018

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants