Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 1. Check to make sure this event should trigger a build
// 2. Trigger a CodeBuild by copying current code to S3 (the CodeBuild source)
// 3. Send a notification that the build is starting (for Slack/etc)
// 4. Set the GitHub status to 'pending' for the sha
// This Lambda should not be considered to be entirely or even mostly
// responsible for the configuration of CodeBuild environment. It should only
// worry about the parts of the configuration that result from the events
// the function is intended to handle.
const url = require('url');
const https = require('https');
const fs = require('fs');
const AWS = require('aws-sdk');
const codebuild = new AWS.CodeBuild({ apiVersion: '2016-10-06' });
const sns = new AWS.SNS({ apiVersion: '2010-03-31' });
const s3 = new AWS.S3({ apiVersion: '2006-03-01' });
const USER_AGENT = 'PRX/Infrastructure (github-event-handler)';
const GITHUB_HEADERS = {
Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`,
Accept: 'application/vnd.github.v3+json',
'User-Agent': USER_AGENT,
};
// Note: The response to this request should be a 201
// https://developer.github.com/v3/repos/statuses/#create-a-status
function updateGitHubStatus(event, build) {
return (new Promise((resolve, reject) => {
console.log('...Updating GitHub status...');
// Get request properties
createSnsTopic(topicName) {
const SNS = new AWS.SNS({ region: 'us-east-1' });
BbPromise.promisifyAll(SNS, { suffix: 'Promised' });
const params = {
Name: topicName,
};
return SNS.createTopicPromised(params);
},
function _scan({eventName}, callback) {
let sns = new aws.SNS()
;(function __scanner (params = {}, callback) {
sns.listTopics(params, function _listTopics(err, results) {
if (err) throw err
let found = results.Topics.find(t => {
let bits = t.TopicArn.split(':')
let it = bits[bits.length - 1]
return it === eventName
})
if (found) {
callback(null, found.TopicArn)
} else if (results.NextToken) {
__scanner({ NextToken: results.NextToken }, callback)
} else {
callback(Error(`topic ${eventName} not found`))
}
})
let errSns = function(event,_err) {
console.log('Running Error Handler');
const sns = new AWS.SNS({region: process.env.AWS_REGION});
let msg = {
"guid": event.guid,
"event":event,
"function":process.env.AWS_LAMBDA_FUNCTION_NAME,
"error": _err.toString()
};
let params = {
Subject: 'Workflow error: ' + event.guid,
Message: JSON.stringify(msg, null, 2),
TargetArn: process.env.ErrorsSns
};
sns.publish(params).promise()
.catch(err => console.log(err)
var AWS = require('aws-sdk');
var sns = new AWS.SNS();
if(process.env.IS_UNIT_TEST === 'true') {
module.exports = function(message, topicArn, cb) {
cb(null, {});
};
} else {
module.exports = function(message, topicArn, cb) {
var params = {
Message: JSON.stringify(message),
TopicArn: topicArn
};
sns.publish(params, cb);
};
}
getClient: ({ config }) => new AWS.SNS(config),
isReady: (client) => client.getSMSAttributes().promise()
.then(function(creds) {
_this.sns = new AWS.SNS({
region: region,
accessKeyId: creds.accessKeyId,
secretAccessKey: creds.secretAccessKey,
sessionToken: creds.sessionToken
});
BbPromise.promisifyAll(_this.sns);
_this.lambda = new AWS.Lambda({
region: region,
accessKeyId: creds.accessKeyId,
secretAccessKey: creds.secretAccessKey,
sessionToken: creds.sessionToken
});
})
}
'use strict';
const AWS = require('aws-sdk');
const cloudFormation = new AWS.CloudFormation({ apiVersion: '2010-05-15' });
const sns = new AWS.SNS({ apiVersion: '2010-03-31' });
const log = require('console-log-level')({ level: process.env.LOG_LEVEL });
module.exports.handler = (event, context, callback) => {
log.trace('Received event to check stacks for automatic deletion with configuration', event);
log.info('Odin is now checking to see if any stacks are worthy of entering Valhalla');
listAllStacks()
.then( stacks => getStacksToDelete(stacks, event))
.then(publishStacksForDeletion)
.then( () => callback(null, 'Finished checking stacks for deletion'))
.catch( err => callback(err));
};
const listAllStacks = () => {
const params = {};
return cloudFormation.describeStacks(params).promise();
const AWS = require('aws-sdk');
const SNS = new AWS.SNS();
const log = require('./log');
const requestContext = require('./requestContext');
function getMessageAttributes() {
let attributes = {};
let ctx = requestContext.get();
for (let key in ctx) {
attributes[key] = {
DataType: 'String',
StringValue: ctx[key]
};
}
return attributes;
}
constructor({ videoId, snsTopicArn, region }) {
super();
this.videoId = videoId;
this.snsTopicArn = snsTopicArn;
this.sns = new AWS.SNS({ region });
}