How to use the @mapbox/cloudfriend.ref function in @mapbox/cloudfriend

To help you get started, we’ve selected a few @mapbox/cloudfriend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hotosm / tasking-manager / scripts / aws / cloudformation / tasking-manager.template.js View on Github external
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"
github hotosm / visualize-change / devops / visualize-change.template.js View on Github external
{
            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"
    }
  },
github mapbox / ecs-watchbot / lib / template.js View on Github external
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
          }
        ]
      }
    }
  };
github mapbox / ecs-watchbot / lib / template.js View on Github external
.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']
github mapbox / ecs-watchbot / lib / template.js View on Github external
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')) },
github mapbox / ecs-watchbot / cloudformation / travis.template.js View on Github external
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') }
  }
};
github mapbox / ecs-watchbot / lib / template.js View on Github external
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'),
github mapbox / mapbox-gl-draw / cloudformation / ci.template.js View on Github external
],
                  "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') }
  }
};
github hotosm / tasking-manager / cloudformation / tasking-manager.template.js View on Github external
}
      }],
      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 }