- site name: nifty-mcclintock-5552c0
Hello, I am trying to write a netlify lambda function to manage the signup process of my users.
I have created an identity-validate function that gets properly triggered when a user signs up.
My goal in this function is to simply post an incoming webhook to our Mattermost server (slack clone) to receive a message in a channel whenever a user signs up.
So I use the standard node module https to POST a request to our site (we use HTTPS as protocol:
const handler = async (event) => {
try {
body = event.body
console.log(body)
payload = JSON.parse(body)
user_email = payload["user"]["email"]
provider = payload["user"]["app_metadata"]["provider"]
full_name = payload["user"]["user_metadata"]["full_name"]
text = "email = " + user_email + " provider=" + provider + " full_name=" + full_name
console.log(text)
const https = require('https')
const data = JSON.stringify({
text: text
})
const options = {
hostname: 'REDACTED',
port: 443,
path: '/hooks/REDACTED',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}
const req = https.request(options, res => {
console.log('statusCode: ' + res["statusCode"])
res.on('data', d => {
console.log("out=" + d)
})
})
req.on('error', error => {
console.error("ERROR")
console.error(error)
})
req.write(data)
req.end()
console.log("fin3")
return {
statusCode: 200,
body: JSON.stringify({ message: "success" }),
}
} catch (error) {
console.log(error)
return { statusCode: 500, body: error.toString() }
}
}
module.exports = { handler }
When I serve the function with netlify functions:serve
, and test it, the HTTPS request is successfully posted :
19:57 $ netlify functions:serve
◈ Ignored general context env var: LC_ALL (defined in process)
◈ Loaded function hello-world.
◈ Loaded function identity-validate.
◈ Functions server is listening on 9999
Request from ::1: POST /.netlify/functions/identity-validate
{ "event": "validate", "instance_id": "78c271e5-85ae-4184-a920-9d7505ad62aa", "user": { "id": "803a0f87-88dc-49e8-bf5e-f2599adb7323", "aud": "", "role": "", "email": "fgarzon+1@gmail.com", "app_metadata": { "provider": "email" }, "user_metadata": { "full_name": "Frederic Garzon" }, "created_at": "2021-11-09T20:36:30.741779Z", "updated_at": "2021-11-09T20:36:30.745095Z" } }
email = fgarzon+1@gmail.com provider=email full_name=Frederic Garzon
fin3
Response with status 200 in 29 ms.
statusCode: 200
out=ok
However, This code does not generate any HTTPS request when run in production : No error, no exception, none of the logs that you see in the code within the request are written, here is the log.
7:23:10 PM: 07625f6e INFO {"event":"validate","instance_id":"78c271e5-85ae-4184-a920-9d7505ad62aa","user":{"id":"13a74cc8-0e26-43ef-a7b6-c054fa1399a8","aud":"","role":"","email":"fgarzon+1@gmail.com","app_metadata":{"provider":"email"},"user_metadata":{"full_name":"rrrr"},"created_at":"2021-11-17T18:23:09.843998Z","updated_at":"2021-11-17T18:23:09.846527Z"}}
7:23:10 PM: 07625f6e INFO email = fgarzon+1@gmail.com provider=email full_name=rrrr
7:23:10 PM: 07625f6e INFO fin3
7:23:10 PM: 07625f6e Duration: 36.35 ms Memory Usage: 57 MB Init Duration: 159.90 m
Is there a limitation in the AWS lambda function that restrict HTTPS requests ? Or do I do something wrong ? (I am a total newbie with node and javascript…)
Thank you in advance for your help