Last active
October 20, 2021 04:32
-
-
Save hy3/85ac1c0180ce30a89312ae57cda9e561 to your computer and use it in GitHub Desktop.
AWS Lambda function sample to trigger Kompira Pigeon via CloudWatch Event.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const https = require('https'); | |
const invokePigeon = (callflowId, guidanceId, parameters) => new Promise((resolve, reject) => { | |
const options = { | |
host: 'xxx.cloud.kompira.jp', // replace to your space domain | |
port: 443, | |
path: '/api/apps/pigeon/chain/invoke', | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
'X-Authorization': 'Token XXXXXX' // replace XXXXXX to your API Token | |
} | |
}; | |
const payload = { | |
params: { | |
callflowId: callflowId, | |
guidanceId: guidanceId, | |
parameters: parameters | |
} | |
}; | |
const req = https.request(options, res => { | |
let buffer = ""; | |
res.on('data', chunk => buffer += chunk); | |
res.on('end', () => resolve(JSON.parse(buffer))); | |
}); | |
req.on('error', e => reject(e.message)); | |
req.write(JSON.stringify(payload)); | |
req.end(); | |
}); | |
exports.handler = async (event, context) => new Promise( async (resolve, reject) => { | |
const callflowId = '00000000-0000-0000-0000-0000000000000'; // replace to your callflow ID | |
const guidanceId = '00000000-0000-0000-0000-0000000000000'; // replace to your guidance ID | |
const message = event.detail.Message; | |
const parameters = { | |
message: message, // will replace {{message}} in guidance | |
}; | |
const response = await invokePigeon(callflowId, guidanceId, parameters); | |
console.log('Pigeon response:\n' + JSON.stringify(response)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment