Example #1
0
def main(args=None):
    parser = ArgumentParser(description="Discover ECS services")
    add_aws_client_arguments(parser)

    parser.add_argument("cluster_name")
    parser.add_argument("container_port")

    args = parser.parse_args(args)

    aws_client = AWSClient("ecs", args)
    ec2_client = AWSClient("ec2", args)
    client = ECSTaskDiscovery(aws_client, ec2_client)
    task_descs = client.find_tasks(args.cluster_name)

    names = []
    for task in task_descs:
        for network_binding in client.find_network_bindings(
                task, args.container_port, args.cluster_name):
            names.append({
                "{#TASKARN}": task["taskArn"],
                "{#BINDIP}": network_binding[1],
                "{#HOSTPORT}": network_binding[0]["hostPort"]
            })
    discovery = {"data": names}
    print(json.dumps(discovery))
def main(args=None):
    parser = ArgumentParser(description="Discover Lambda functions")
    add_aws_client_arguments(parser)

    args = parser.parse_args(args)

    aws_client = AWSClient("lambda", args)
    client = LambdaDiscovery(aws_client)

    result = client.get_functions()
    functions = result['Functions']

    # Max function return count is 50
    # if n(functions)>50 pagnation token "NextMarker" will be returned
    while 'NextMarker' in result:
        result = client.get_functions(pagination_token=result['NextMarker'])
        functions.extend(result['Functions'])

    discover_functions = []
    for function in functions:
        discover_functions.append({
            '{#FUNCTIONNAME}': function['FunctionName'],
            '{#DESCRIPTION}': function['Description']
        })

    discovery = {'data': discover_functions}
    print(json.dumps(discovery))
Example #3
0
def main(args=None):
    parser = ArgumentParser(description="Retrieve AWS CloudWatch metrics")
    add_aws_client_arguments(parser)

    parser.add_argument("--timeshift",
                        type=int,
                        default=0,
                        help="Time shift for interval")

    parser.add_argument("namespace", help="AWS namespace. e.g. AWS/ECS")
    parser.add_argument("metric", help="Metric to obtain")
    parser.add_argument("interval", type=int, help="Statistic interval")
    parser.add_argument("statistic", help="Statistic to retrieve. e.g. Sum")
    parser.add_argument("dimensions", help="Dimension filter")

    args = parser.parse_args(args)
    dimensions = list()
    if len(args.dimensions) > 0:
        for dimension in args.dimensions.split(","):
            instance = dimension.split("=")
            dimensions.append(dict(zip(("Name", "Value"), instance)))

    aws_client = AWSClient("cloudwatch", args)
    client = CloudWatchMetric(aws_client)
    value = client.get_metric(args.interval, args.metric, args.namespace,
                              args.statistic, dimensions, args.timeshift)
    if value == -1:
        print("")
    else:
        print(value)
Example #4
0
def main(args=None):
    parser = ArgumentParser(description="Get S3 bucket object contents")
    add_aws_client_arguments(parser)

    parser.add_argument("bucket_name", help="S3 bucket name")
    parser.add_argument("object_key", help="S3 object key")
    parser.add_argument("encoding", default="utf-8", help="Object encoding")

    args = parser.parse_args(args)

    aws_client = AWSResourceClient("s3", args)
    client = S3BucketObjectGet(aws_client)
    contents = client.s3_bucket_object_get(args.bucket_name, args.object_key,
                                           args.encoding)
    print(contents)
Example #5
0
def main(args=None):
    parser = ArgumentParser(description="Discover RDS services")
    add_aws_client_arguments(parser)

    parser.add_argument("cluster_identifier")

    args = parser.parse_args(args)

    aws_client = AWSClient("rds", args)
    client = RDSDiscovery(aws_client)
    members = client.find_cluster_members(args.cluster_identifier)

    identifiers = []
    for member in members:
        identifiers.append({
                "{#DB_IDENTIFIER}": member["DBInstanceIdentifier"]
            })
    discovery = {"data": identifiers}
    print(json.dumps(discovery))
Example #6
0
def main(args=None):
    parser = ArgumentParser(description="Calculate statistics of S3 bucket")
    add_aws_client_arguments(parser)

    available_stats = ["oldest", "newest", "size"]
    parser.add_argument("bucket_name", help="S3 bucket name")
    parser.add_argument("stat",
                        help="Statistic to calculate",
                        choices=available_stats)

    args = parser.parse_args(args)

    aws_client = AWSClient("s3", args)
    client = S3BucketStat(aws_client)
    value = client.s3_bucket_stat(args.bucket_name, args.stat)
    if value == -1:
        print("")
    else:
        print(value)
Example #7
0
def main(args=None):
    parser = ArgumentParser(description="Discover ECS services")
    add_aws_client_arguments(parser)

    parser.add_argument("cluster_name")

    args = parser.parse_args(args)

    aws_client = AWSClient("ecs", args)
    client = ECSDiscovery(aws_client)
    serviceArns = client.find_services(args.cluster_name)

    names = []
    for arn in serviceArns:
        names.append({
            "{#CLUSTER_NAME}": args.cluster_name,
            "{#SERVICE_NAME}": arn.split("/")[-1]
        })
    discovery = {"data": names}
    print(json.dumps(discovery))
def main(args=None):

    parser = ArgumentParser(description="")

    # Create aws client and parse arguments
    add_aws_client_arguments(parser)
    parser.add_argument("-n", "--namespace", help="Namespace of AWS service")
    parser.add_argument("-f",
                        "--function_name",
                        help="Function that is to be called in boto3 library")
    parser.add_argument(
        "-a",
        "--arguments",
        help=
        "Arguments that are given to the funcion. Arguments are given in form of a1=a,a2=b... Supports only string arguments."
    )
    args = parser.parse_args(args)

    # Create aws connection and call specified function
    aws_client = AWSClient(args.namespace, args)
    caller = FunctionCaller(aws_client, args.function_name, args.arguments)
    result = caller.get_results()

    print(json.dumps(result, default=unserializable_to_str))