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

Adding lambda logResult output variable #451

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/tasks/LambdaInvokeFunction/TaskOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ export class TaskOperations {
try {
const data: Lambda.InvocationResponse = await this.lambdaClient.invoke(params).promise()
let outValue = ''
let outLogsValue = ''
if (data.Payload) {
outValue = data.Payload.toString()
}

if (data.LogResult) {
outLogsValue = data.LogResult
}

// don't echo the value into the normal logs in case it contains sensitive data
tl.debug(tl.loc('ReceivedOutput', outValue))

Expand All @@ -46,6 +51,11 @@ export class TaskOperations {
tl.setVariable(this.taskParameters.outputVariable, outValue)
}

if (this.taskParameters.outputLogsVariable) {
console.log(tl.loc('SettingOutputLogsVariable', this.taskParameters.outputLogsVariable))
tl.setVariable(this.taskParameters.outputLogsVariable, outLogsValue)
}

console.log(tl.loc('TaskCompleted', this.taskParameters.functionName))
} catch (err) {
console.error(tl.loc('FunctionInvokeFailed'), err)
Expand Down
4 changes: 3 additions & 1 deletion src/tasks/LambdaInvokeFunction/TaskParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface TaskParameters {
invocationType: string
logType: string
outputVariable: string
outputLogsVariable: string
}

export function buildTaskParameters(): TaskParameters {
Expand All @@ -22,6 +23,7 @@ export function buildTaskParameters(): TaskParameters {
payload: getInputOrEmpty('payload'),
invocationType: getInputOrEmpty('invocationType'),
logType: getInputOrEmpty('logType'),
outputVariable: getInputOrEmpty('outputVariable')
outputVariable: getInputOrEmpty('outputVariable'),
outputLogsVariable: getInputOrEmpty('outputLogsVariable')
}
}
10 changes: 10 additions & 0 deletions src/tasks/LambdaInvokeFunction/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
"helpMarkDown": "The name of the variable that will contain the function output on task completion. The variable can be used as $(variableName) to refer to the function result in subsequent tasks.",
"required": false
},
{
"name": "outputLogsVariable",
"type": "string",
"label": "Output Logs Variable",
"defaultValue": "",
"groupName": "OutputOptions",
"helpMarkDown": "The name of the variable that will contain the last 4 KB of log data produced by your Lambda function. The variable can be used as $(variableName) to refer to the function result in subsequent tasks.",
"required": false
},
{
"name": "logType",
"type": "pickList",
Expand Down Expand Up @@ -119,6 +128,7 @@
"InvokingFunction": "Invoking function %s",
"FunctionInvokeFailed": "Error invoking function",
"SettingOutputVariable": "Setting output variable %s with the function output",
"SettingOutputLogsVariable": "Setting output logs variable %s with the function output logs",
"ReceivedOutput": "Received output %s from function",
"FunctionDoesNotExist": "Function %s does not exist",
"TaskCompleted": "Completed invocation of Lambda function %s"
Expand Down
4 changes: 3 additions & 1 deletion tests/taskTests/lambdaInvoke/lambdaInvoke-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const baseTaskParameters: TaskParameters = {
payload: '',
invocationType: '',
logType: '',
outputVariable: ''
outputVariable: '',
outputLogsVariable: ''
}

const awsResponseThrows = {
Expand Down Expand Up @@ -60,6 +61,7 @@ describe('Lambda Invoke', () => {
expect.assertions(3)
const taskParameters = { ...baseTaskParameters }
taskParameters.outputVariable = 'something'
taskParameters.outputLogsVariable = 'something'
await assertPayloadCorrect(
taskParameters,
jest.fn(() => {
Expand Down