Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
Port: 5000,
Protocol: "HTTP",
VpcId: cf.importValue(cf.join("-", ["hotosm-network-production", "default-vpc", cf.region])),
TargetType: "ip",
Matcher: {
HttpCode: "200,202,302,304"
}
}
},
MLEnablerALB: {
Type: "AWS::ElasticLoadBalancingV2::LoadBalancer",
Properties: {
Name: cf.stackName,
SecurityGroups: [
cf.importValue(
cf.join("-", ["hotosm-network-production-production-elbs-security-group", cf.region])
)
],
Subnets: cf.split(",", cf.ref("ELBSubnets")),
Type: "application"
}
},
MLEnablerHTTPSListener: {
Type: 'AWS::ElasticLoadBalancingV2::Listener',
Properties: {
Certificates: [ {
CertificateArn: cf.arn('acm', cf.ref('SSLCertificateIdentifier'))
}],
DefaultActions: [{
Type: 'forward',
TargetGroupArn: cf.ref('MLEnablerTargetGroup')
}],
Environment: unpackEnv(options.env, mounts.mountPoints),
MountPoints: mounts.mountPoints,
Command: ['watchbot', 'listen', `${options.command}`],
Ulimits: [
{
Name: 'nofile',
SoftLimit: 10240,
HardLimit: 10240
}
],
ReadonlyRootFilesystem: !options.writableFilesystem,
LogConfiguration: {
LogDriver: 'awslogs',
Options: {
'awslogs-group': cf.ref(prefixed('LogGroup')),
'awslogs-region': cf.region,
'awslogs-stream-prefix': options.serviceVersion
}
}
}
],
Volumes: mounts.volumes
}
};
if (options.reservation.memory)
Resources[prefixed('Task')].Properties.ContainerDefinitions[0].Memory =
options.reservation.memory;
if (options.reservation.softMemory)
Resources[
prefixed('Task')
ArnEquals: {
'aws:SourceArn': cf.ref(prefixed('Topic'))
}
}
}
]
}
}
};
Resources[prefixed('LogGroup')] = {
Type: 'AWS::Logs::LogGroup',
Properties: {
LogGroupName: cf.join('-', [
cf.stackName,
cf.region,
options.prefix.toLowerCase()
]),
RetentionInDays: 14
}
};
if (options.dashboard) {
Resources[prefixed('Dashboard')] = {
Type: 'AWS::CloudWatch::Dashboard',
Properties: {
DashboardName: cf.join('-', [cf.ref('AWS::StackName'), prefixed(''), cf.region]),
DashboardBody: cf.sub(dashboard, {
WatchbotQueue: cf.getAtt(prefixed('Queue'), 'QueueName'),
WatchbotDeadLetterQueue: cf.getAtt(prefixed('DeadLetterQueue'), 'QueueName'),
WatchbotService: cf.getAtt(prefixed('Service'), 'Name'),
Cluster: options.cluster,
"commands": {
"01enable_cfn_hup": {
"command": "systemctl enable cfn-hup.service"
},
"02start_cfn_hup": {
"command": "systemctl start cfn-hup.service"
}
}
}
}
},
Properties: {
IamInstanceProfile: cf.ref('TaskingManagerEC2InstanceProfile'),
ImageId: 'ami-0565af6e282977273',
InstanceType: 'c5d.large',
SecurityGroups: [cf.importValue(cf.join('-', ['hotosm-network-production', cf.ref('NetworkEnvironment'), 'ec2s-security-group', cf.region]))],
UserData: cf.userData([
'#!/bin/bash',
'set -x',
'export DEBIAN_FRONTEND=noninteractive',
'export LC_ALL="en_US.UTF-8"',
'export LC_CTYPE="en_US.UTF-8"',
'dpkg-reconfigure --frontend=noninteractive locales',
'sudo apt-get -y update',
'sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade',
'sudo add-apt-repository ppa:deadsnakes/ppa -y',
'sudo apt-get update',
'sudo apt-get -y install python3.6',
'sudo apt-get -y install python3.6-dev',
'sudo apt-get -y install python3.6-venv',
'sudo apt-get -y install curl',
'curl -o install-node10.sh -sL https://deb.nodesource.com/setup_10.x',