This topic was automatically generated from Slack. You can find the original thread here.
Vincent Lo : I am trying to get a custom response from a Lambda call back to a webhook/HTTP trigger but regardless of what I do, I always get the default “Success!
To customize this response, check out our docs here” message. I have tried many combinations of the code below
const AWS = require('aws-sdk')
const { accessKeyId, secretAccessKey } = auths.aws
const { region, FunctionName, eventData } = params
const lambda = new AWS.Lambda({
accessKeyId,
secretAccessKey,
region
})
const lambdaParams = {
Payload: eventData,
FunctionName,
InvocationType: "RequestResponse",
LogType: "Tail",
}
this.res = await lambda.invoke(lambdaParams).promise()
this.res = await $respond({
status: 200,
headers: { "my-custom-header": "value" },
body: { message: "My custom response" } // This can be any string, object, or Buffer
})
Dylan Sather (Pipedream) : just to confirm, are you using a Pipedream workflow, or an event source?
Can you remove the this.res = await portion of the $respond code?
$respond() should run synchronously the way you’re using it (so no need for the await ), and you’ll see the HTTP response that’s issued for a specific HTTP response in the observability of the trigger step (in steps.trigger.response), when you select a specific event, so you don’t need to add this.res to save the response:
Vincent Lo : yes, I am using a Pipedream workflow, through a webhook trigger to a Jotform. I then invoke a Lamda and am trying to respond with an event json eventually
thank you for your response, i shall eagerly try it now!
Dylan Sather (Pipedream) : got it, so currently because of how event sources trigger workflows, you can’t issue a custom response all the way from the workflow back to the client that called the event source. Do you need to issue a custom response based on the response from Lambda, or do you just need to issue a more custom, static response?
If you just want to return a custom, static response from the event source itself, visit Sources - Pipedream and select your Typeform source, click on the Configuration tab and you’ll see the code for that source. You’ll need to do two things:
First, change the line that reads http: "$.interface.http", to
Dylan Sather (Pipedream) : ah sorry, that should go within the run method near the bottom. Since the HTTP response happens asynchronously (technically it happens after the code runs), you can actually put it anywhere. I like to put it near the top of the run method to clarify that we’re issuing a response, so that section should read:
Over time we’re planning to unify more about workflows and event sources / components, so there should be fewer inconsistencies with HTTP responses and other features in the future!