Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"02_config-amazon-cloudwatch-agent": {
"files": {
'/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json': {
"content": cf.join("\n", [
"{\"logs\": {",
"\"logs_collected\": {",
"\"files\": {",
"\"collect_list\": [",
"{",
"\"file_path\": \"/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log\",",
cf.sub("\"log_group_name\": \"${AWS::StackName}.log\","),
cf.sub("\"log_stream_name\": \"${AWS::StackName}-cloudwatch-agent.log\","),
"\"timezone\": \"UTC\"",
"},",
"{",
cf.sub("\"file_path\": \"${TaskingManagerLogDirectory}/tasking-manager.log\","),
cf.sub("\"log_group_name\": \"${AWS::StackName}.log\","),
cf.sub("\"log_stream_name\": \"${AWS::StackName}.log\","),
"\"timezone\": \"UTC\"",
"}]}},",
cf.sub("\"log_stream_name\": \"${AWS::StackName}-logs\","),
"\"force_flush_interval\" : 15",
"}}"
])
}
}
},
// Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent.
"03_restart_amazon-cloudwatch-agent": {
"commands": {
"01_stop_service": {
"command": "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop"
function buildLambda(options) {
let fn = {
Resources: {}
};
// all function parameters available as environment variables
fn.Resources[options.name] = {
Type: 'AWS::Lambda::Function',
Properties: {
Code: {
S3Bucket: cf.ref('CodeS3Bucket'),
S3Key: cf.join([cf.ref('CodeS3Prefix'), cf.ref('GitSha'), '.zip'])
},
Role: cf.if('HasDispatchSnsArn', cf.getAtt('LambdaCfnDispatchRole', 'Arn'), cf.getAtt('LambdaCfnRole', 'Arn')),
Description: cf.stackName,
Environment: {
Variables: {}
}
}
};
fn.Resources[options.name].Properties.Timeout = setLambdaTimeout(options.timeout);
fn.Resources[options.name].Properties.MemorySize = setLambdaMemorySize(options.memorySize);
fn.Resources[options.name].Properties.Runtime = setLambdaRuntine(options.runtime);
fn.Resources[options.name].Properties.Handler = setLambdaHandler(options.handler);
return fn;
}
if (Object.keys(functionTemplate.Parameters).length > 60) {
throw new Error('More than 60 parameters specified');
}
// since build functions may create their own parameters outside of
// the buildParameters step, this is called after all functions
// have been run, gathers all parameters and injects them into the lambda
// environment configuration
// TODO: is this possible when embedding?
if (!functionTemplate.Variables) {
functionTemplate.Variables = {};
}
// make some global env vars available
functionTemplate.Variables.StackName = cf.stackName;
functionTemplate.Variables.Region = cf.region;
functionTemplate.Variables.AccountId = cf.accountId;
functionTemplate.Variables.StackId = cf.stackId;
for (let param in functionTemplate.Parameters) {
functionTemplate.Variables[param] = cf.ref(param);
}
if (!functionTemplate.Resources) {
functionTemplate.Resources[options.name] = {};
}
functionTemplate.Resources[options.name].Properties.Environment.Variables = functionTemplate.Variables;
// Variables object is not valid CFN
delete functionTemplate.Variables;
throw new Error('More than 60 parameters specified');
}
// since build functions may create their own parameters outside of
// the buildParameters step, this is called after all functions
// have been run, gathers all parameters and injects them into the lambda
// environment configuration
// TODO: is this possible when embedding?
if (!functionTemplate.Variables) {
functionTemplate.Variables = {};
}
// make some global env vars available
functionTemplate.Variables.StackName = cf.stackName;
functionTemplate.Variables.Region = cf.region;
functionTemplate.Variables.AccountId = cf.accountId;
functionTemplate.Variables.StackId = cf.stackId;
for (let param in functionTemplate.Parameters) {
functionTemplate.Variables[param] = cf.ref(param);
}
if (!functionTemplate.Resources) {
functionTemplate.Resources[options.name] = {};
}
functionTemplate.Resources[options.name].Properties.Environment.Variables = functionTemplate.Variables;
// Variables object is not valid CFN
delete functionTemplate.Variables;
// compile any additional built-in policy objects into role
test('[template validation] defaults', async (assert) => {
const builtWithDefaults = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com'
}));
const tmp = path.join(os.tmpdir(), crypto.randomBytes(8).toString('hex'));
fs.writeFileSync(tmp, JSON.stringify(builtWithDefaults));
try {
await cf.validate(tmp);
assert.pass('template is valid');
} catch (err) {
assert.ifError(err, 'template is not valid');
}
test('[template]', () => {
assert.throws(
() => template(),
/options.service is required/,
'throws when missing required options'
);
const builtWithDefaults = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com'
}));
expect(builtWithDefaults).toMatchSnapshot('defaults');
const setsAllOptions = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
permissions: [
{
test('[template validation] options set', async (assert) => {
const setsAllOptions = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
permissions: [
{
Effect: 'Allow',
Action: 's3:GetObject',
Resource: 'arn:aws:s3:::bucket/*'
}
],
env: {
MyKey: 'MyValue'
},
prefix: 'Soup',
family: 'abc-123',
test('[template validation] fifo queue', async (assert) => {
const fifo = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com',
fifo: true
}));
const tmp = path.join(os.tmpdir(), crypto.randomBytes(8).toString('hex'));
fs.writeFileSync(tmp, JSON.stringify(fifo));
try {
await cf.validate(tmp);
assert.pass('template is valid');
} catch (err) {
assert.ifError(err, 'template is not valid');
expect(setsAllLowCPU).toMatchSnapshot('all-properties-low-CPU');
const fifo = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com',
fifo: true
}));
expect(fifo).toMatchSnapshot('fifo');
const fifoMaxSize = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com',
fifo: true,
maxSize: 50
}));
expect(fifoMaxSize).toMatchSnapshot('fifoMaxSize');
});
memory: 512,
softMemory: 128,
cpu: 0
},
privileged: true,
reduce: true,
messageTimeout: 300,
messageRetention: 1096,
deadletterThreshold: 50,
notificationEmail: 'hello@mapbox.pagerduty.com'
}));
expect(setsAllLowCPU).toMatchSnapshot('all-properties-low-CPU');
const fifo = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com',
fifo: true
}));
expect(fifo).toMatchSnapshot('fifo');
const fifoMaxSize = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com',