I am invoking a lambda function from jenkins declarative pipeline. Now i want to use its output in other the pipeline. I am trying the following code :
def health=invokeLambda([awsAccessKeyId: 'xxxx', awsRegion: 'rrrrr', awsSecretKey: 'kkkkk', functionName: 'yyyyyy', payload: '', synchronous: true]);
when i try echo "$health"
iam getting null.
Does anyone know how to use the output of lambda function in jenkinsfile?
I Assume you are using the AWS Lambda Plugin which is a relatively old plugin and was designed for freestyle jobs and not for pipelines.
While you can use it in a pipeline script you will not be able to get the returned value as the plugin is designed to update environment variables with the results - which works grate in freestyle jobs but is not supported in pipelines.
To achieve what you want you can use the new pipeline oriented AWS Steps Plugin which contains many AWS related steps which are designed for pipeline usage and allow easy access to the output of the steps. It is also more secure and allows much more capabilities then the old plugin - especially for pipelines.
In your case you can use the invokeLambda
step that will return the output is you expect:
withAWS(region:'eu-central-1', credentials:'nameOfSystemCredentials') {
def result = invokeLambda(
functionName: 'myLambdaFunction',
payload: [ "key": "value", "anotherkey" : [ "another", "value"] ]
)
}