Coder Social home page Coder Social logo

jicowan / service-discovery Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 2.0 39.74 MB

CLI for registering services with the AWS Service Discovery Service

TeX 3.79% HTML 4.09% Python 89.75% Shell 0.02% CSS 0.38% JavaScript 0.09% C++ 1.00% C 0.84% Fortran 0.05%
service-discovery elastic-container-service route-53 aws

service-discovery's Introduction

service-discovery

On 3/18/18 the Elastic Container Service (ECS) added support for service discovery. To register an ECS service with the Service Discovery Service, you first need to create a namespace. A namespace is a Route 53 private hosted zone that your ECS services can use to discover other ECS services, e.g. acme.local. After creating a namespace, you register your service with the Service Discovery Service. This returns a registry ARN which you add to your ECS service's service definition. A walk-through of the Service Discovery Service is available here. As you'll see, there are a lot of steps involved if you use the AWS CLI. This is a simple CLI to create service discovery namespaces and register services under those namespaces. You can download the executable from the /dist folder. This CLI only creates A records and only works in us-east-1 at the moment as I originally designed it to work with Fargate which at the time was only available in us-east-1.

Usage

Create

Creates a namespace and registers a service with a namespace.

sd create [--vpc <vpc-id>] [--namespace <namespace-name>] [--service <service-name>]

Sample output: 
+---------------------+----------------------+---------------------------------+
|    Namespace-Id     |      Service-Id      |           Service-Arn           |
+=====================+======================+=================================+
| ns-jkazzonvbupl7unu | srv-sjjhzf7xwwhvhkdw | arn:aws:servicediscovery:us-    |
|                     |                      | east-1:012345678901:service     |
|                     |                      | /srv-sjjhzf7xwwhvhkdw           |
+---------------------+----------------------+---------------------------------+

To register an ECS service with the service discovery service, add the service ARN to the service's service definition. For example:

{
    cluster='fargate',
    serviceName=service_name + '-svc',
    taskDefinition=task_name,
    serviceRegistries=[
        {
            'registryArn': service_arn
        }
    ],
    desiredCount=1,
    platformVersion='1.1.0',
    launchType='FARGATE',
    networkConfiguration={
        'awsvpcConfiguration': {
            'subnets': [
                'subnet-f8bc52a2',
            ],
            'securityGroups': [
                'sg-592a062c',
            ],
            'assignPublicIp': 'ENABLED'
        }
    }
}

Delete

Deletes a service or namespace

sd delete [--namespace-id <namespace-id>] [--service-id <service-id>]

List

Ouputs the services and namespaces in a region

sd list [--services] [--namespaces]

Sample output: 
+----------------------+------------------------------------------+------------+
|          Id          |                   Arn                    |    Name    |
+======================+==========================================+============+
| srv-sjjhzf7xwwhvhkdw | arn:aws:servicediscovery:us-             | ya         |
|                      | east-1:012345678901:service/srv-         |            |
|                      | sjjhzf7xwwhvhkdw                         |            |
+----------------------+------------------------------------------+------------+

+-------------+---------------------+-----------------------------+------------+
|    Type     |         Id          |             Arn             |    Name    |
+=============+=====================+=============================+============+
| DNS_PRIVATE | ns-jkazzonvbupl7unu | arn:aws:servicediscovery    | yada.local |
|             |                     | :us-east-1:012345678901:nam |            |
|             |                     | espace/ns-jkazzonvbupl7unu  |            |
+-------------+---------------------+-----------------------------+------------+

Describe

Outputs the IP addresses of services registered with the namespace

sd describe [--namespace-id <namespace-id>]

Sample output: 
[
    {
        "ResourceRecords": [
            {
                "Value": "ns-1536.awsdns-00.co.uk."
            },
            {
                "Value": "ns-0.awsdns-00.com."
            },
            {
                "Value": "ns-1024.awsdns-00.org."
            },
            {
                "Value": "ns-512.awsdns-00.net."
            }
        ],
        "Type": "NS",
        "Name": "yada.local.",
        "TTL": 172800
    },
    {
        "ResourceRecords": [
            {
                "Value": "ns-1536.awsdns-00.co.uk. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"
            }
        ],
        "Type": "SOA",
        "Name": "yada.local.",
        "TTL": 900
    }
]

service-discovery's People

Contributors

jicowan avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.