Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
AutoScalingGroupName: cf.ref('TaskingManagerASG'),
PolicyType: 'TargetTrackingScaling',
TargetTrackingConfiguration: {
TargetValue: 600,
PredefinedMetricSpecification: {
PredefinedMetricType: 'ALBRequestCountPerTarget',
ResourceLabel: cf.join('/', [
cf.select(1,
cf.split('loadbalancer/',
cf.select(5,
cf.split(':', cf.ref("TaskingManagerLoadBalancer"))
)
)
),
cf.select(5,
cf.split(':', cf.ref("TaskingManagerTargetGroup"))
)
])
}
},
Cooldown: 600
}
},
TaskingManagerLaunchConfiguration: {
Type: "AWS::AutoScaling::LaunchConfiguration",
Metadata: {
"AWS::CloudFormation::Init": {
"configSets": {
"default": [
"01_setupCfnHup",
"02_config-amazon-cloudwatch-agent",
"03_restart_amazon-cloudwatch-agent"
{
Effect: "Allow",
Principal: {
Service: ["ec2.amazonaws.com"]
},
Action: ["sts:AssumeRole"]
}
]
},
RoleName: cf.join("-", [cf.stackName, "ec2", "role"])
}
},
VisualizeChangeEC2InstanceProfile: {
Type: "AWS::IAM::InstanceProfile",
Properties: {
Roles: [cf.ref("VisualizeChangeEC2Role")],
InstanceProfileName: cf.join("-", [cf.stackName, "ec2", "instance", "profile"])
}
},
VisualizeChangeLoadBalancer: {
Type: "AWS::ElasticLoadBalancingV2::LoadBalancer",
Properties: {
Name: cf.stackName,
SecurityGroups: [
cf.importValue(
cf.join("-", ["hotosm-network-production", cf.ref("Environment"), "elbs-security-group", cf.region])
)
],
Subnets: cf.split(",", cf.ref("ELBSubnets")),
Type: "application"
}
},
ResourceId: cf.join([
'service/',
options.cluster,
'/',
cf.getAtt(prefixed('Service'), 'Name')
]),
MinCapacity: options.minSize,
MaxCapacity: options.maxSize,
RoleARN: cf.getAtt(prefixed('ScalingRole'), 'Arn')
}
};
Resources[prefixed('ScaleUp')] = {
Type: 'AWS::ApplicationAutoScaling::ScalingPolicy',
Properties: {
ScalingTargetId: cf.ref(prefixed('ScalingTarget')),
PolicyName: cf.sub('${AWS::StackName}-scale-up'),
PolicyType: 'StepScaling',
StepScalingPolicyConfiguration: {
AdjustmentType: 'ChangeInCapacity',
Cooldown: 300,
MetricAggregationType: 'Average',
StepAdjustments: [
{
ScalingAdjustment: cf.getAtt(prefixed('CustomScalingResource'), 'ScalingAdjustment'),
MetricIntervalLowerBound: 0.0
}
]
}
}
};
.then((attrs) => {
return cw.putMetricData({
Namespace: 'Mapbox/ecs-watchbot',
MetricData: [{
MetricName: 'TotalMessages',
Dimensions: [{ Name: 'QueueName', Value: ${'\'${QueueName}\''} }],
Value: Number(attrs.Attributes.ApproximateNumberOfMessagesNotVisible) +
Number(attrs.Attributes.ApproximateNumberOfMessages)
}]
}).promise();
})
.then((metric) => callback(null, metric))
.catch((err) => callback(err));
}
`, {
QueueUrl: cf.ref(prefixed('Queue')),
QueueName: cf.getAtt(prefixed('Queue'), 'QueueName')
})
},
Runtime: 'nodejs10.x'
}
};
Resources[prefixed('LambdaTotalMessagesRole')] = {
Type: 'AWS::IAM::Role',
Properties: {
AssumeRolePolicyDocument: {
Statement: [
{
Effect: 'Allow',
Principal: { Service: ['lambda.amazonaws.com'] },
Action: ['sts:AssumeRole']
readCapacityUnits: 30,
writeCapacityUnits: 30,
alarmPeriods: 24,
failedPlacementAlarmPeriods: 1,
deadletterThreshold: 10,
deadletterAlarm: true,
dashboard: true,
fifo: false
},
options
);
const prefixed = (name) => `${options.prefix}${name}`;
const ref = {
logGroup: cf.ref(prefixed('LogGroup')),
topic: options.fifo ? undefined : cf.ref(prefixed('Topic')),
queueUrl: cf.ref(prefixed('Queue')),
queueArn: cf.getAtt(prefixed('Queue'), 'Arn'),
queueName: cf.getAtt(prefixed('Queue'), 'QueueName'),
notificationTopic: cf.ref(prefixed('NotificationTopic'))
};
const unpackEnv = (env, mountPoints) => {
return Object.keys(env).reduce(
(unpacked, key) => {
unpacked.push({ Name: key, Value: env[key] });
return unpacked;
},
[
{ Name: 'WorkTopic', Value: options.fifo ? undefined : cf.ref(prefixed('Topic')) },
{ Name: 'QueueUrl', Value: cf.ref(prefixed('Queue')) },
Statement: [
{
Action: ['cloudformation:ValidateTemplate'],
Effect: 'Allow',
Resource: '*'
}
]
}
}
]
}
},
AccessKey: {
Type: 'AWS::IAM::AccessKey',
Properties: {
UserName: cf.ref('User')
}
}
},
Outputs: {
AccessKeyId: { Value: cf.ref('AccessKey') },
SecretAccessKey: { Value: cf.getAtt('AccessKey', 'SecretAccessKey') }
}
};
Statement: [
{
Action: [
'dynamodb:GetItem',
'dynamodb:PutItem',
'dynamodb:UpdateItem'
],
Effect: 'Allow',
Resource: tableArn
}
]
}
}
};
ref.progressTable = cf.ref(prefixed('ProgressTable'));
options.env.ProgressTable = tableArn;
}
Resources[prefixed('Task')] = {
Type: 'AWS::ECS::TaskDefinition',
Properties: {
TaskRoleArn: cf.ref(prefixed('Role')),
Family: options.family,
ContainerDefinitions: [
{
Name: cf.join('-', [prefixed(''), cf.stackName]),
Image: cf.join([
cf.accountId,
'.dkr.ecr.',
cf.findInMap('EcrRegion', cf.region, 'Region'),
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::mapbox-gl-js/plugins/mapbox-gl-draw/*"
]
}
]
}
}
]
}
},
AccessKey: {
Type: 'AWS::IAM::AccessKey',
Properties: {
UserName: cf.ref('User')
}
}
},
Outputs: {
AccessKeyId: { Value: cf.ref('AccessKey') },
SecretAccessKey: { Value: cf.getAtt('AccessKey', 'SecretAccessKey') }
}
};
}
}],
LoadBalancerArn: cf.ref('TaskingManagerLoadBalancer'),
Port: 80,
Protocol: 'HTTP'
}
},
TaskingManagerRDS: {
Type: 'AWS::RDS::DBInstance',
Properties: {
Engine: 'postgres',
DBName: cf.if('UseASnapshot', cf.noValue, cf.ref('PostgresDB')),
EngineVersion: '9.5.15',
MasterUsername: cf.if('UseASnapshot', cf.noValue, cf.ref('PostgresUser')),
MasterUserPassword: cf.if('UseASnapshot', cf.noValue, cf.ref('PostgresPassword')),
AllocatedStorage: cf.ref('DatabaseSize'),
StorageType: 'gp2',
DBInstanceClass: 'db.m3.large', //rethink here
DBSnapshotIdentifier: cf.if('UseASnapshot', cf.ref('DBSnapshot'), cf.noValue),
VPCSecurityGroups: [cf.importValue(cf.join('-', ['hotosm-network-production', cf.ref('Environment'), 'ec2s-security-group', cf.region]))],
}
}
};
module.exports = { Parameters, Resources, Conditions }