Skip to content

Instantly share code, notes, and snippets.

@sammarks sammarks/lambda.js

Created May 7, 2020
Embed
What would you like to do?
Slack notifications from AWS Amplify
const https = require('https')
exports.handler = async (event) => {
const sns = event.Records[0].Sns.Message
let color = ''
let message = ''
if (sns.includes('build status is FAILED')) {
color = '#E52E59'
message = 'Release to My Company **production** failed.'
} else if (sns.includes('build status is SUCCEED')) {
color = '#21E27C'
message = 'Release to My Company **production** succeeded.'
} else if (sns.includes(`build status is STARTED`)) {
color = '#3788DD'
message = 'Release to My Company **production** has started...'
}
const data = JSON.stringify({
attachments: [
{
'mrkdwn_in': ['text'],
fallback: message,
color,
text: message
}
]
})
return new Promise((resolve, reject) => {
const request = https.request(process.env.WEBHOOK_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length,
}
}, (res) => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', (d) => process.stdout.write(d))
res.on('end', () => resolve())
})
request.write(data)
request.end()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.