in source/custom-resource/index.js [133:217]
Launch: moment().utc().format()
}
};
let _usageMetrics = new UsageMetrics();
_usageMetrics.sendAnonymousMetric(_metric).then((data) => {
console.log(data);
console.log('Annonymous metrics successfully sent.');
}).catch((err) => {
console.log(`Sending anonymous launch metric failed: ${err}`);
});
sendResponse(event, callback, context.logStreamName, 'SUCCESS', {});
} else {
sendResponse(event, callback, context.logStreamName, 'SUCCESS');
}
} else {
sendResponse(event, callback, context.logStreamName, 'SUCCESS');
}
}
if (event.RequestType === 'Update') {
if (event.ResourceProperties.customAction === 'copyS3assets') {
let _s3Helper = new S3Helper();
_s3Helper.copyAssets(event.ResourceProperties.manifestKey,
event.ResourceProperties.sourceS3Bucket, event.ResourceProperties.sourceS3key,
event.ResourceProperties.destS3Bucket).then((data) => {
responseStatus = 'SUCCESS';
responseData = {};
sendResponse(event, callback, context.logStreamName, responseStatus, responseData);
}).catch((err) => {
responseData = {
Error: `Copy of website assets failed`
};
console.log([responseData.Error, ':\n', err].join(''));
sendResponse(event, callback, context.logStreamName, responseStatus, responseData);
});
} else if (event.ResourceProperties.customAction === 'putConfigFile') {
let _s3Helper = new S3Helper();
console.log(event.ResourceProperties.configItem);
_s3Helper.putConfigFile(event.ResourceProperties.configItem, event.ResourceProperties.destS3Bucket, event.ResourceProperties.destS3key).then((data) => {
responseStatus = 'SUCCESS';
responseData = data;
sendResponse(event, callback, context.logStreamName, responseStatus, responseData);
}).catch((err) => {
responseData = {
Error: `Saving config file to ${event.ResourceProperties.destS3Bucket}/${event.ResourceProperties.destS3key} failed`
};
console.log([responseData.Error, ':\n', err].join(''));
sendResponse(event, callback, context.logStreamName, responseStatus, responseData);
});
} else if (event.ResourceProperties.customAction === 'checkSourceBuckets') {
let _s3Helper = new S3Helper();
_s3Helper.validateBuckets(event.ResourceProperties.sourceBuckets).then((data) => {
responseStatus = 'SUCCESS';
responseData = {};
sendResponse(event, callback, context.logStreamName, responseStatus, responseData);
}).catch((err) => {
responseData = {
Error: `Could not find the following source bucket(s) in your account: ${err}. Please specify at least one source bucket that exists within your account and try again. If specifying multiple source buckets, please ensure that they are comma-separated.`
};
console.log(responseData.Error);
sendResponse(event, callback, context.logStreamName, responseStatus, responseData, responseData.Error);
});
} else if (event.ResourceProperties.customAction === 'createUuid') {
responseStatus = 'SUCCESS';
responseData = {
UUID: uuidv4()
};
sendResponse(event, callback, context.logStreamName, responseStatus, responseData);
} else if (event.ResourceProperties.customAction === 'sendMetric') {
responseStatus = 'SUCCESS';
if (event.ResourceProperties.anonymousData === 'Yes') {
let _metric = {
Solution: event.ResourceProperties.solutionId,
UUID: event.ResourceProperties.UUID,
TimeStamp: moment().utc().format('YYYY-MM-DD HH:mm:ss.S'),
Data: {