This documentation is for Version 1 of the Amazon CLI only. For documentation related to Version 2 of the Amazon CLI, see the Version 2 User Guide.
Amazon Cloud Map examples using Amazon CLI
The following code examples show you how to perform actions and implement common scenarios by using the Amazon Command Line Interface with Amazon Cloud Map.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use create-private-dns-namespace
.
- Amazon CLI
-
To create a private DNS namespace
The following
create-private-dns-namespace
example creates a private DNS namespace.aws servicediscovery create-private-dns-namespace \ --name
example.com
\ --vpcvpc-1c56417b
Output:
{ "OperationId": "gv4g5meo7ndmeh4fqskygvk23d2fijwa-k9302yzd" }
To confirm that the operation succeeded, you can run
get-operation
. For more information, see get-operation. For more information, see Creating namespaces
in the Amazon Cloud Map Developer Guide. -
For API details, see CreatePrivateDnsNamespace
in Amazon CLI Command Reference.
-
The following code example shows how to use create-service
.
- Amazon CLI
-
To create a service
The following
create-service
example creates a service.aws servicediscovery create-service \ --name
myservice
\ --namespace-idns-ylexjili4cdxy3xm
\ --dns-config"NamespaceId=ns-ylexjili4cdxy3xm,RoutingPolicy=MULTIVALUE,DnsRecords=[{Type=A,TTL=60}]"
Output:
{ "Service": { "Id": "srv-p5zdwlg5uvvzjita", "Arn": "arn:aws:servicediscovery:us-west-2:803642222207:service/srv-p5zdwlg5uvvzjita", "Name": "myservice", "NamespaceId": "ns-ylexjili4cdxy3xm", "DnsConfig": { "NamespaceId": "ns-ylexjili4cdxy3xm", "RoutingPolicy": "MULTIVALUE", "DnsRecords": [ { "Type": "A", "TTL": 60 } ] }, "CreateDate": 1587081768.334, "CreatorRequestId": "567c1193-6b00-4308-bd57-ad38a8822d25" } }
For more information, see Creating services
in the Amazon Cloud Map Developer Guide. -
For API details, see CreateService
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-namespace
.
- Amazon CLI
-
To delete a namespace
The following
delete-namespace
example deletes a namespace.aws servicediscovery delete-namespace \ --id
ns-ylexjili4cdxy3xm
Output:
{ "OperationId": "gv4g5meo7ndmeh4fqskygvk23d2fijwa-k98y6drk" }
To confirm that the operation succeeded, you can run
get-operation
. For more information, see get-operation. For more information, see Deleting namespaces
in the Amazon Cloud Map Developer Guide. -
For API details, see DeleteNamespace
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-service
.
- Amazon CLI
-
To delete a service
The following
delete-service
example deletes a service.aws servicediscovery delete-service \ --id
srv-p5zdwlg5uvvzjita
This command produces no output.
For more information, see Deleting services
in the Amazon Cloud Map Developer Guide. -
For API details, see DeleteService
in Amazon CLI Command Reference.
-
The following code example shows how to use deregister-instance
.
- Amazon CLI
-
To deregister a service instance
The following
deregister-instance
example deregisters a service instance.aws servicediscovery deregister-instance \ --service-id
srv-p5zdwlg5uvvzjita
\ --instance-idmyservice-53
Output:
{ "OperationId": "4yejorelbukcjzpnr6tlmrghsjwpngf4-k98rnaiq" }
To confirm that the operation succeeded, you can run
get-operation
. For more information, see get-operation. For more information, see Deregistering service instances
in the Amazon Cloud Map Developer Guide. -
For API details, see DeregisterInstance
in Amazon CLI Command Reference.
-
The following code example shows how to use discover-instances
.
- Amazon CLI
-
To discover registered instances
The following
discover-instances
example discovers registered instances.aws servicediscovery discover-instances \ --namespace-name
example.com
\ --service-namemyservice
\ --max-results10
\ --health-statusALL
Output:
{ "Instances": [ { "InstanceId": "myservice-53", "NamespaceName": "example.com", "ServiceName": "myservice", "HealthStatus": "UNKNOWN", "Attributes": { "AWS_INSTANCE_IPV4": "172.2.1.3", "AWS_INSTANCE_PORT": "808" } } ] }
-
For API details, see DiscoverInstances
in Amazon CLI Command Reference.
-
The following code example shows how to use get-operation
.
- Amazon CLI
-
To get the result of an operation
The following
get-operation
example gets the result of an operation.aws servicediscovery get-operation \ --operation-id
gv4g5meo7ndmeh4fqskygvk23d2fijwa-k9302yzd
Output:
{ "Operation": { "Id": "gv4g5meo7ndmeh4fqskygvk23d2fijwa-k9302yzd", "Type": "CREATE_NAMESPACE", "Status": "SUCCESS", "CreateDate": 1587055860.121, "UpdateDate": 1587055900.469, "Targets": { "NAMESPACE": "ns-ylexjili4cdxy3xm" } } }
-
For API details, see GetOperation
in Amazon CLI Command Reference.
-
The following code example shows how to use list-instances
.
- Amazon CLI
-
To list service instances
The following
list-instances
example lists service instances.aws servicediscovery list-instances \ --service-id
srv-qzpwvt2tfqcegapy
Output:
{ "Instances": [ { "Id": "i-06bdabbae60f65a4e", "Attributes": { "AWS_INSTANCE_IPV4": "172.2.1.3", "AWS_INSTANCE_PORT": "808" } } ] }
For more information, see Viewing a list of service instances
in the Amazon Cloud Map Developer Guide. -
For API details, see ListInstances
in Amazon CLI Command Reference.
-
The following code example shows how to use list-namespaces
.
- Amazon CLI
-
To list namespaces
The following
list-namespaces
example lists namespaces.aws servicediscovery list-namespaces
Output:
{ "Namespaces": [ { "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-a3ccy2e7e3a7rile", "CreateDate": 1585354387.357, "Id": "ns-a3ccy2e7e3a7rile", "Name": "local", "Properties": { "DnsProperties": { "HostedZoneId": "Z06752353VBUDTC32S84S" }, "HttpProperties": { "HttpName": "local" } }, "Type": "DNS_PRIVATE" }, { "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-pocfyjtrsmwtvcxx", "CreateDate": 1586468974.698, "Description": "My second namespace", "Id": "ns-pocfyjtrsmwtvcxx", "Name": "My-second-namespace", "Properties": { "DnsProperties": {}, "HttpProperties": { "HttpName": "My-second-namespace" } }, "Type": "HTTP" }, { "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-ylexjili4cdxy3xm", "CreateDate": 1587055896.798, "Id": "ns-ylexjili4cdxy3xm", "Name": "example.com", "Properties": { "DnsProperties": { "HostedZoneId": "Z09983722P0QME1B3KC8I" }, "HttpProperties": { "HttpName": "example.com" } }, "Type": "DNS_PRIVATE" } ] }
For more information, see Viewing a list of namespaces
in the Amazon Cloud Map Developer Guide. -
For API details, see ListNamespaces
in Amazon CLI Command Reference.
-
The following code example shows how to use list-services
.
- Amazon CLI
-
To list services
The following
list-services
example lists services.aws servicediscovery list-services
Output:
{ "Services": [ { "Id": "srv-p5zdwlg5uvvzjita", "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjita", "Name": "myservice", "DnsConfig": { "RoutingPolicy": "MULTIVALUE", "DnsRecords": [ { "Type": "A", "TTL": 60 } ] }, "CreateDate": 1587081768.334 } ] }
For more information, see Viewing a list of services
in the Amazon Cloud Map Developer Guide. -
For API details, see ListServices
in Amazon CLI Command Reference.
-
The following code example shows how to use register-instance
.
- Amazon CLI
-
To register a service instance
The following
register-instance
example registers a service instance.aws servicediscovery register-instance \ --service-id
srv-p5zdwlg5uvvzjita
\ --instance-idmyservice-53
\ --attributes=AWS_INSTANCE_IPV4=172.2.1.3,AWS_INSTANCE_PORT=808Output:
{ "OperationId": "4yejorelbukcjzpnr6tlmrghsjwpngf4-k95yg2u7" }
To confirm that the operation succeeded, you can run
get-operation
. For more information, see get-operation. For more information, see Registering instances
in the Amazon Cloud Map Developer Guide. -
For API details, see RegisterInstance
in Amazon CLI Command Reference.
-