This documentation is for Version 1 of the AWS CLI only. For documentation related to Version 2 of the AWS CLI, see the Version 2 User Guide.
AWS Cloud Map examples using AWS CLI
The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with AWS 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-http-namespace.
- AWS CLI
-
To create an HTTP namespace
The following
create-http-namespaceexample creates an HTTP namespaceexample.com.aws servicediscovery create-http-namespace \ --nameexample.com\ --creator-request-idexample-request-idOutput:
{ "OperationId": "gv4g5meo7ndmeh4fqskygvk23d2fijwa-k9302yzd" }To confirm that the operation succeeded, you can run
get-operation. For more information, see get-operation .For more information about creating a namespace, see Creating an AWS Cloud Map namespace to group application services in the AWS Cloud Map Developer Guide.
-
For API details, see CreateHttpNamespace
in AWS CLI Command Reference.
-
The following code example shows how to use create-private-dns-namespace.
- AWS CLI
-
To create a private DNS namespace
The following
create-private-dns-namespaceexample creates a private DNS namespace.aws servicediscovery create-private-dns-namespace \ --nameexample.com\ --vpcvpc-1c56417bOutput:
{ "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 AWS Cloud Map Developer Guide.
-
For API details, see CreatePrivateDnsNamespace
in AWS CLI Command Reference.
-
The following code example shows how to use create-public-dns-namespace.
- AWS CLI
-
To create an public DNS namespace
The following
create-public-dns-namespaceexample creates an public DNS namespaceexample.com.aws servicediscovery create-public-dns-namespace \ --nameexample-public-dns.com\ --creator-request-idexample-public-request-id\ --propertiesDnsProperties={SOA={TTL=60}}Output:
{ "OperationId": "gv4g5meo7ndmeh4fqskygvk23d2fijwa-k9302yzd" }To confirm that the operation succeeded, you can run
get-operation.For more information about creating a namespace, see Creating an AWS Cloud Map namespace to group application services in the AWS Cloud Map Developer Guide.
-
For API details, see CreatePublicDnsNamespace
in AWS CLI Command Reference.
-
The following code example shows how to use create-service.
- AWS CLI
-
Example 1: To create a service using namespace ID
The following
create-serviceexample creates a service.aws servicediscovery create-service \ --namemyservice\ --namespace-idns-ylexjili4cdxy3xm\ --dns-config"RoutingPolicy=MULTIVALUE,DnsRecords=[{Type=A,TTL=60}]"Output:
{ "Service": { "Id": "srv-abcd1234xmpl5678", "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678", "ResourceOwner": "123456789012", "Name": "myservice", "NamespaceId": "ns-abcd1234xmpl5678", "DnsConfig": { "NamespaceId": "ns-abcd1234xmpl5678", "RoutingPolicy": "MULTIVALUE", "DnsRecords": [ { "Type": "A", "TTL": 60 } ] }, "Type": "DNS_HTTP", "CreateDate": "2025-08-18T13:45:31.023000-05:00", "CreatorRequestId": "abcd1234-5678-90ab-cdef-xmpl12345678", "CreatedByAccount": "123456789012" } }For more information, see Creating an AWS Cloud Map service for an application component in the AWS Cloud Map Developer Guide.
Example 2: To create a service using namespace ARN
The following
create-serviceexample creates a service using a namespace ARN instead of namespace ID. Specifying a namespace ARN is necessary when creating a service in a shared namespace.aws servicediscovery create-service \ --namemyservice-arn\ --namespace-idarn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678\ --dns-config"RoutingPolicy=MULTIVALUE,DnsRecords=[{Type=A,TTL=60}]"Output:
{ "Service": { "Id": "srv-abcd1234xmpl5678", "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678", "ResourceOwner": "123456789012", "Name": "myservice-arn", "NamespaceId": "ns-abcd1234xmpl5678", "DnsConfig": { "NamespaceId": "ns-abcd1234xmpl5678", "RoutingPolicy": "MULTIVALUE", "DnsRecords": [ { "Type": "A", "TTL": 60 } ] }, "Type": "DNS_HTTP", "CreateDate": "2025-08-18T13:45:31.023000-05:00", "CreatorRequestId": "abcd1234-5678-90ab-cdef-xmpl12345678", "CreatedByAccount": "123456789012" } }For more information, see Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see CreateService
in AWS CLI Command Reference.
-
The following code example shows how to use delete-namespace.
- AWS CLI
-
Example 1: To delete a namespace
The following
delete-namespaceexample deletes a namespace.aws servicediscovery delete-namespace \ --idns-abcd1234xmpl5678Output:
{ "OperationId": "abcd1234-5678-90ab-cdef-xmpl12345678" }To confirm that the operation succeeded, you can run
get-operation. For more information, see get-operation .For more information, see Deleting an AWS Cloud Map namespace in the AWS Cloud Map Developer Guide.
Example 2: To delete a namespace using namespace ARN
The following
delete-namespaceexample deletes a namespace using its ARN.aws servicediscovery delete-namespace \ --idarn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678Output:
{ "OperationId": "abcd1234-5678-90ab-cdef-xmpl12345678" }For more information, see Deleting an AWS Cloud Map namespace in the AWS Cloud Map Developer Guide.
-
For API details, see DeleteNamespace
in AWS CLI Command Reference.
-
The following code example shows how to use delete-service-attributes.
- AWS CLI
-
Example 1: To delete a service attribute
The following
delete-service-attributesexample deletes a service attribute with the keyPortthat is associated with the specified service.aws servicediscovery delete-service-attributes \ --service-idsrv-abcd1234xmpl5678\ --attributesPortThis command produces no output.
For more information, see AWS Cloud Map services in the AWS Cloud Map Developer Guide.
Example 2: To delete a service attribute using ARN
The following
delete-service-attributesexample deletes a service attribute using the service ARN. Specifying the ARN is necessary for deleting attributes associated with services created in namespaces shared with your account.aws servicediscovery delete-service-attributes \ --service-idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678\ --attributesPortThis command produces no output.
For more information, see AWS Cloud Map services and Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see DeleteServiceAttributes
in AWS CLI Command Reference.
-
The following code example shows how to use delete-service.
- AWS CLI
-
Example 1: To delete a service
The following
delete-serviceexample deletes a service.aws servicediscovery delete-service \ --idsrv-abcd1234xmpl5678This command produces no output.
For more information, see Deleting an AWS Cloud Map service in the AWS Cloud Map Developer Guide.
Example 2: To delete a service using ARN
The following
delete-serviceexample deletes a service using its ARN.aws servicediscovery delete-service \ --idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678This command produces no output.
For more information, see Deleting an AWS Cloud Map service in the AWS Cloud Map Developer Guide.
-
For API details, see DeleteService
in AWS CLI Command Reference.
-
The following code example shows how to use deregister-instance.
- AWS CLI
-
Example 1: To deregister a service instance
The following
deregister-instanceexample deregisters a service instance.aws servicediscovery deregister-instance \ --service-idsrv-p5zdwlg5uvvzjita\ --instance-idmyservice-53Output:
{ "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 AWS Cloud Map Developer Guide.
Example 2: To deregister a service instance using service ARN for shared namespaces
The following
deregister-instanceexample deregisters a service instance using a service ARN instead of service ID. Specifying an ARN is required when deregistering instances from services created in namespaces that are shared with your account.aws servicediscovery deregister-instance \ --service-idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjita\ --instance-idweb-server-01Output:
{ "OperationId": "gv4g5meo7ndmkqjrhpn39wk42xmpl" }For more information, see Shared AWS Cloud Map namespaces and Deregistering an AWS Cloud Map service instance in the AWS Cloud Map Developer Guide.
-
For API details, see DeregisterInstance
in AWS CLI Command Reference.
-
The following code example shows how to use discover-instances-revision.
- AWS CLI
-
Example 1: To discover the revision of an instance
The following
discover-instances-revisionexample discovers the increasing revision of an instance.aws servicediscovery discover-instances-revision \ --namespace-nameexample.com\ --service-namemyserviceOutput:
{ "InstancesRevision": 123456 }For more information, see AWS Cloud Map service instances in the AWS Cloud Map Developer Guide.
Example 2: To discover the revision of instances from a specific owner account
The following
discover-instances-revisionexample discovers the revision of instances from a specific owner account. The owner-account parameter is necessary for instances in namespaces that are shared with your account.aws servicediscovery discover-instances-revision \ --namespace-nameshared-namespace\ --service-nameshared-service\ --owner-account123456789111Output:
{ "InstancesRevision": 1234567890 }For more information, see Shared AWS Cloud Map namespaces and AWS Cloud Map service instances in the AWS Cloud Map Developer Guide.
-
For API details, see DiscoverInstancesRevision
in AWS CLI Command Reference.
-
The following code example shows how to use discover-instances.
- AWS CLI
-
Example 1: To discover registered instances
The following
discover-instancesexample discovers registered instances.aws servicediscovery discover-instances \ --namespace-nameexample.com\ --service-namemyservice\ --max-results10\ --health-statusALLOutput:
{ "Instances": [ { "InstanceId": "myservice-53", "NamespaceName": "example.com", "ServiceName": "myservice", "HealthStatus": "UNKNOWN", "Attributes": { "AWS_INSTANCE_IPV4": "172.2.1.3", "AWS_INSTANCE_PORT": "808" } } ], "InstancesRevision": 85648075627387284 }For more information, see AWS Cloud Map service instances in the AWS Cloud Map Developer Guide.
Example 2: To discover instances from a specific owner account
The following
discover-instancesexample discovers registered instances from a specific owner account. This parameter is necessary to discover instances in namespaces that are shared with your account.aws servicediscovery discover-instances \ --namespace-nameshared-namespace\ --service-nameshared-service\ --owner-account123456789111Output:
{ "Instances": [ { "InstanceId": "shared-instance-1234", "NamespaceName": "shared-namespace", "ServiceName": "shared-service", "HealthStatus": "HEALTHY", "Attributes": { "AWS_INSTANCE_IPV4": "203.0.113.75", "AWS_INSTANCE_PORT": "80" } } ], "InstancesRevision": 1234567890 }For more information, see Shared AWS Cloud Map namespaces and AWS Cloud Map service instances in the AWS Cloud Map Developer Guide.
-
For API details, see DiscoverInstances
in AWS CLI Command Reference.
-
The following code example shows how to use get-instance.
- AWS CLI
-
Example 1: To get the details of an instance
The following
get-instanceexample gets the attributes of a service.aws servicediscovery get-instance \ --service-idsrv-e4anhexample0004--instance-idi-abcd1234Output:
{ "ResourceOwner": "123456789012", "Instance": { "Id": "arn:aws:servicediscovery:us-west-2:111122223333;:service/srv-e4anhexample0004", "Attributes": { "AWS_INSTANCE_IPV4": "192.0.2.44", "AWS_INSTANCE_PORT": "80", "color": "green", "region": "us-west-2", "stage": "beta" }, "CreatedByAccount": "123456789012" } }For more information, see AWS Cloud Map service instances in the AWS Cloud Map Developer Guide.
Example 2: To get the details of an instance using service ARN for shared namespaces
The following
get-instanceexample gets the attributes of an instance using a service ARN instead of service ID. Specifying an ARN is required when getting details of instances associated with namespaces that are shared with your account. The instance returned in this example was registered by account123456789111in a namespace owned by account123456789012.aws servicediscovery get-instance \ --service-idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjita\ --instance-idweb-server-01Output:
{ "ResourceOwner": "123456789012", "Instance": { "Id": "web-server-01", "Attributes": { "AWS_INSTANCE_IPV4": "203.0.113.15", "AWS_INSTANCE_PORT": "80" }, "CreatedByAccount": "123456789111" } }For more information about cross-account namespace sharing, see Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see GetInstance
in AWS CLI Command Reference.
-
The following code example shows how to use get-instances-health-status.
- AWS CLI
-
Example 1: To get the health status of instances associated with a service
The following
get-instances-health-statusexample gets the health status of instances associated with the specified service.aws servicediscovery get-instances-health-status \ --service-idsrv-e4anhexample0004Output:
{ "Status": { "i-abcd1234": "HEALTHY", "i-abcd1235": "UNHEALTHY" } }For more information, see AWS Cloud Map service instances in the AWS Cloud Map Developer Guide.
Example 2: To get the health status of instances using service ARN for shared namespaces
The following
get-instances-health-statusexample gets the health status of instances using a service ARN instead of service ID. Specifying an ARN is required when getting health status for instances associated with namespaces that are shared with the requester's account.aws servicediscovery get-instances-health-status \ --service-idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjitaOutput:
{ "Status": { "web-server-01": "HEALTHY", "web-server-02": "UNHEALTHY" } }For more information, see AWS Cloud Map service instances and Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see GetInstancesHealthStatus
in AWS CLI Command Reference.
-
The following code example shows how to use get-namespace.
- AWS CLI
-
Example 1: To get the details of a namespace
The following
get-namespaceexample retrieves information about the specified namespace.aws servicediscovery get-namespace \ --idns-abcd1234xmpl5678Output:
{ "Namespace": { "Id": "ns-abcd1234xmpl5678", "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678", "ResourceOwner": "123456789012", "Name": "example-http.com", "Type": "HTTP", "Description": "Example.com AWS Cloud Map HTTP Namespace", "Properties": { "DnsProperties": {}, "HttpProperties": { "HttpName": "example-http.com" } }, "CreateDate": "2024-02-23T13:35:21.874000-06:00", "CreatorRequestId": "abcd1234-5678-90ab-cdef-xmpl12345678" } }For more information, see AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
Example 2: To get the details of a namespace using ARN
The following
get-namespaceexample retrieves information about the specified namespace using its ARN. Specifying the ARN is necessary for retreiving details of a namespace shared with your account.aws servicediscovery get-namespace \ --idarn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678Output:
{ "Namespace": { "Id": "ns-abcd1234xmpl5678", "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678", "ResourceOwner": "123456789012", "Name": "example-http.com", "Type": "HTTP", "Description": "Example.com AWS Cloud Map HTTP Namespace", "Properties": { "DnsProperties": {}, "HttpProperties": { "HttpName": "example-http.com" } }, "CreateDate": "2024-02-23T13:35:21.874000-06:00", "CreatorRequestId": "abcd1234-5678-90ab-cdef-xmpl12345678" } }For more information, see Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see GetNamespace
in AWS CLI Command Reference.
-
The following code example shows how to use get-operation.
- AWS CLI
-
Example 1: To get the result of an operation
The following
get-operationexample gets the result of a namespace creation operation.aws servicediscovery get-operation \ --operation-idabcd1234xmpl5678abcd1234xmpl5678-abcd1234Output:
{ "Operation": { "Id": "abcd1234xmpl5678abcd1234xmpl5678-abcd1234", "Type": "CREATE_NAMESPACE", "Status": "SUCCESS", "CreateDate": "2025-01-13T13:35:21.874000-06:00", "UpdateDate": "2025-01-13T13:36:02.469000-06:00", "Targets": { "NAMESPACE": "ns-abcd1234xmpl5678" } } }For more information, see Creating an AWS Cloud Map namespace to group application services in the AWS Cloud Map Developer Guide.
Example 2: To get an operation from a specific owner account
The following
get-operationexample gets the result of an operation associated with a specific namespace owner account. This parameter is necessary to get the result of operations associated with namespaces shared with your account.aws servicediscovery get-operation \ --operation-idabcd1234xmpl5678abcd1234xmpl5678-abcd1234\ --owner-account123456789111Output:
{ "Operation": { "Id": "abcd1234xmpl5678abcd1234xmpl5678-abcd1234", "OwnerAccount": "123456789111", "Type": "CREATE_NAMESPACE", "Status": "SUCCESS", "CreateDate": "2025-01-13T13:35:21.874000-06:00", "UpdateDate": "2025-01-13T13:36:02.469000-06:00", "Targets": { "NAMESPACE": "ns-abcd1234xmpl5678" } } }For more information, see Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see GetOperation
in AWS CLI Command Reference.
-
The following code example shows how to use get-service-attributes.
- AWS CLI
-
Example 1: To get the attributes of a service
The following
get-service-attributesexample gets the attributes of a service.aws servicediscovery get-service-attributes \ --service-idsrv-abcd1234xmpl5678Output:
{ "ServiceAttributes": { "ServiceArn": "arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678", "ResourceOwner": "123456789012", "Attributes": { "Port": "80" } } }For more information, see AWS Cloud Map services in the AWS Cloud Map Developer Guide.
Example 2: To get the attributes of a service using ARN
The following
get-service-attributesexample gets the attributes of a service using its ARN. Specifying an ARN is necessary for getting attributes of a service created in a namespace shared with your account.aws servicediscovery get-service-attributes \ --service-idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678Output:
{ "ServiceAttributes": { "ServiceArn": "arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678", "ResourceOwner": "123456789012", "Attributes": { "Port": "80" } } }For more information, see AWS Cloud Map services and Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see GetServiceAttributes
in AWS CLI Command Reference.
-
The following code example shows how to use get-service.
- AWS CLI
-
Example 1: To get the settings of a service
The following
get-serviceexample gets the settings of a specified service.aws servicediscovery get-service \ --idsrv-abcd1234xmpl5678Output:
{ "Service": { "Id": "srv-abcd1234xmpl5678", "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678", "ResourceOwner": "123456789012", "Name": "test-service", "NamespaceId": "ns-abcd1234xmpl5678", "DnsConfig": {}, "Type": "HTTP", "CreateDate": "2025-08-18T13:53:02.775000-05:00", "CreatorRequestId": "abcd1234-5678-90ab-cdef-xmpl12345678", "CreatedByAccount": "123456789012" } }For more information, see AWS Cloud Map services in the AWS Cloud Map Developer Guide.
Example 2: To get the settings of a service using ARN
The following
get-serviceexample gets the settings of a specified service using its ARN. Specifying the ARN is necessary when retrieving information about a service created in a namespace that is shared with your account. The caller account123456789111created the service in a namespace shared by account123456789012.aws servicediscovery get-service \ --idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678Output:
{ "Service": { "Id": "srv-abcd1234xmpl5678", "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678", "ResourceOwner": "123456789012", "Name": "test-service", "NamespaceId": "ns-abcd1234xmpl5678", "DnsConfig": {}, "Type": "HTTP", "CreateDate": "2025-08-18T13:53:02.775000-05:00", "CreatorRequestId": "abcd1234-5678-90ab-cdef-xmpl12345678", "CreatedByAccount": "123456789111" } }For more information, see Creating an AWS Cloud Map service for an application component and Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see GetService
in AWS CLI Command Reference.
-
The following code example shows how to use list-instances.
- AWS CLI
-
Example 1: To list service instances
The following
list-instancesexample lists service instances.aws servicediscovery list-instances \ --service-idsrv-qzpwvt2tfqcegapyOutput:
{ "Instances": [ { "Id": "i-06bdabbae60f65a4e", "Attributes": { "AWS_INSTANCE_IPV4": "172.2.1.3", "AWS_INSTANCE_PORT": "808" }, "CreatedByAccount": "123456789012" } ], "ResourceOwner": "123456789012" }For more information, see Listing AWS Cloud Map service instances in the AWS Cloud Map Developer Guide.
Example 2: To list service instances using service ARN
The following
list-instancesexample lists service instances using a service ARN instead of service ID. Specifying an ARN is required when listing instances associated with namespaces that are shared with your account.aws servicediscovery list-instances \ --service-idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjitaOutput:
{ "ResourceOwner": "123456789012", "Instances": [ { "Id": "web-server-01", "Attributes": { "AWS_INSTANCE_IPV4": "203.0.113.15", "AWS_INSTANCE_PORT": "80" }, "CreatedByAccount": "123456789012" }, { "Id": "web-server-02", "Attributes": { "AWS_INSTANCE_IPV4": "203.0.113.16", "AWS_INSTANCE_PORT": "80" }, "CreatedByAccount": "123456789012" } ] }For more information about cross-account namespace sharing, see Shared AWS Cloud Map namespaces and Listing AWS Cloud Map service instances in the AWS Cloud Map Developer Guide.
-
For API details, see ListInstances
in AWS CLI Command Reference.
-
The following code example shows how to use list-namespaces.
- AWS CLI
-
Example 1: To list namespaces
The following
list-namespacesexample lists namespaces.aws servicediscovery list-namespacesOutput:
{ "Namespaces": [ { "Id": "ns-abcd1234xmpl5678", "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678", "ResourceOwner": "123456789012", "Name": "local", "Type": "DNS_PRIVATE", "Properties": { "DnsProperties": { "HostedZoneId": "Z06752353VBUDTC32S84S", "SOA": {} }, "HttpProperties": { "HttpName": "local" } }, "CreateDate": "2023-07-17T13:37:27.872000-05:00" }, { "Id": "ns-abcd1234xmpl9012", "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl9012", "ResourceOwner": "123456789012", "Name": "My-second-namespace", "Type": "HTTP", "Description": "My second namespace", "Properties": { "DnsProperties": { "SOA": {} }, "HttpProperties": { "HttpName": "My-second-namespace" } }, "CreateDate": "2023-11-14T10:35:47.840000-06:00" } ] }For more information, see Listing AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
Example 2: To list namespaces shared by other accounts
The following
list-namespacesexample lists namespaces that are shared with the caller account by other AWS accounts using theRESOURCE_OWNERfilter.aws servicediscovery list-namespaces \ --filtersName=RESOURCE_OWNER,Values=OTHER_ACCOUNTS,Condition=EQOutput:
{ "Namespaces": [ { "Id": "ns-abcd1234xmpl5678", "Arn": "arn:aws:servicediscovery:us-west-2:123456789111:namespace/ns-abcd1234xmpl5678", "ResourceOwner": "123456789111", "Name": "shared-namespace", "Type": "HTTP", "Description": "Namespace shared from another account", "Properties": { "DnsProperties": { "SOA": {} }, "HttpProperties": { "HttpName": "shared-namespace" } }, "CreateDate": "2025-01-13T13:35:21.874000-06:00" } ] }For more information, see Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see ListNamespaces
in AWS CLI Command Reference.
-
The following code example shows how to use list-operations.
- AWS CLI
-
To list operations that meet the specified criteria
The following
list-operationsexample lists operations that have a status ofPENDINGorSUCCESS.aws servicediscovery list-operations \ --service-idsrv-e4anhexample0004\ --filtersName=STATUS,Condition=IN,Values=PENDING,SUCCESSOutput:
{ "Operations": [ { "Id": "76yy8ovhpdz0plmjzbsnqgnrqvpv2qdt-kexample", "Status": "SUCCESS" }, { "Id": "prysnyzpji3u2ciy45nke83x2zanl7yk-dexample", "Status": "SUCCESS" }, { "Id": "ko4ekftir7kzlbechsh7xvcdgcpk66gh-7example", "Status": "PENDING" } ] }For more information, see What is AWS Cloud Map? in the AWS Cloud Map Developer Guide.
-
For API details, see ListOperations
in AWS CLI Command Reference.
-
The following code example shows how to use list-services.
- AWS CLI
-
Example 1: To list services
The following
list-servicesexample lists services.aws servicediscovery list-servicesOutput:
{ "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 Listing AWS Cloud Map services in a namespace in the AWS Cloud Map Developer Guide.
Example 2: To list services created in shared namespaces
The following
list-servicesexample lists services that are created in namespaces shared with the caller account123456789012by other AWS accounts using theRESOURCE_OWNERfilter.aws servicediscovery list-services \ --filtersName=RESOURCE_OWNER,Values=OTHER_ACCOUNTS,Condition=EQOutput:
{ "Services": [ { "Id": "srv-abcd1234xmpl5678", "Arn": "arn:aws:servicediscovery:us-west-2:123456789111:service/srv-abcd1234xmpl5678", "ResourceOwner": "123456789111", "Name": "shared-service", "NamespaceId": "ns-abcd1234xmpl5678", "Type": "HTTP", "Description": "Service in shared namespace", "DnsConfig": {}, "CreateDate": "2025-01-13T13:35:21.874000-06:00", "CreatorRequestId": "abcd1234-5678-90ab-cdef-xmpl12345678", "CreatedByAccount": "123456789012" } ] }For more information, see Shared AWS Cloud Map namespaces and Listing AWS Cloud Map services in a namespace in the AWS Cloud Map Developer Guide.
-
For API details, see ListServices
in AWS CLI Command Reference.
-
The following code example shows how to use list-tags-for-resource.
- AWS CLI
-
To list tags associated with the specified resource
The following
list-tags-for-resourceexample lists tags for the specified resource.aws servicediscovery list-tags-for-resource \ --resource-arnarn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-e4anhexample0004Output:
{ "Tags": [ { "Key": "Project", "Value": "Zeta" }, { "Key": "Department", "Value": "Engineering" } ] }For more information, see Tagging your AWS Cloud Map resources in the AWS Cloud Map Developer Guide.
-
For API details, see ListTagsForResource
in AWS CLI Command Reference.
-
The following code example shows how to use register-instance.
- AWS CLI
-
Example 1: To register a service instance using service ID
The following
register-instanceexample registers a service instance.aws servicediscovery register-instance \ --service-idsrv-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 about registering an instance, see Registering a resource as an AWS Cloud Map service instance in the AWS Cloud Map Developer Guide.
Example 2: To register a service instance using service ARN
The following
register-instanceexample registers a service instance using a service ARN. Specifying the ARN is required when registering instances in services that are shared with your account.aws servicediscovery register-instance \ --service-idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjita\ --instance-idweb-server-01\ --attributes=AWS_INSTANCE_IPV4=203.0.113.15,AWS_INSTANCE_PORT=80Output:
{ "OperationId": "gv4g5meo7ndmkqjrhpn39wk42xmpl" }For more information about cross-account namespace sharing, see Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see RegisterInstance
in AWS CLI Command Reference.
-
The following code example shows how to use tag-resource.
- AWS CLI
-
To associate tags with the specified resource
The following
tag-resourceexample associates aDepartmenttag with the valueEngineeringwith the specified namespace.aws servicediscovery tag-resource \ --resource-arnarn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-e4anhexample0004\ --tagsKey=Department,Value=EngineeringThis command produces no output.
For more information, see Tagging your AWS Cloud Map resources in the AWS Cloud Map Developer Guide.
-
For API details, see TagResource
in AWS CLI Command Reference.
-
The following code example shows how to use untag-resource.
- AWS CLI
-
To remove tags from the specified resource
The following
untag-resourceexample removes aDepartmenttag from the specified namespace.aws servicediscovery untag-resource \ --resource-arnarn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-e4anhexample0004\ --tagsKey=Department,Value=EngineeringThis command produces no output.
For more information, see Tagging your AWS Cloud Map resources in the AWS Cloud Map Developer Guide.
-
For API details, see UntagResource
in AWS CLI Command Reference.
-
The following code example shows how to use update-http-namespace.
- AWS CLI
-
Example 1: To update an HTTP namespace
The following
update-http-namespaceexample updates the specified HTTP namespace's description.aws servicediscovery update-http-namespace \ --idns-abcd1234xmpl5678\ --updater-request-idabcd1234-5678-90ab-cdef-xmpl12345678\ --namespace Description="The updated namespace description."Output:
{ "OperationId": "abcd1234-5678-90ab-cdef-xmpl12345678" }To confirm that the operation succeeded, you can run
get-operation. For more information, see get-operation .For more information, see AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
Example 2: To update an HTTP namespace using ARN
The following
update-http-namespaceexample updates the specified HTTP namespace using its ARN.aws servicediscovery update-http-namespace \ --idarn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678\ --updater-request-idabcd1234-5678-90ab-cdef-xmpl12345678\ --namespace Description="The updated namespace description."Output:
{ "OperationId": "abcd1234-5678-90ab-cdef-xmpl12345678" }For more information, see AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see UpdateHttpNamespace
in AWS CLI Command Reference.
-
The following code example shows how to use update-instance-custom-health-status.
- AWS CLI
-
Example 1: To update a custom health check
The following
update-instance-custom-health-statusexample updates the status of the custom health check for the specified service and example service instance toHEALTHY.aws servicediscovery update-instance-custom-health-status \ --service-idsrv-e4anhexample0004\ --instance-idexample\ --statusHEALTHYThis command produces no output.
For more information, see AWS Cloud Map service health check configuration in the AWS Cloud Map Developer Guide.
Example 2: To update a custom health check using service ARN
The following
update-instance-custom-health-statusexample updates the status of the custom health check using a service ARN. The ARN is required when updating health status for instances associated with namespaces that are shared with the your account.aws servicediscovery update-instance-custom-health-status \ --service-idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjita\ --instance-idweb-server-01\ --statusHEALTHYThis command produces no output.
For more information, see AWS Cloud Map service health check configuration and Cross-account AWS Cloud Map namespace sharing in the AWS Cloud Map Developer Guide.
-
For API details, see UpdateInstanceCustomHealthStatus
in AWS CLI Command Reference.
-
The following code example shows how to use update-private-dns-namespace.
- AWS CLI
-
Example 1: To update a private DNS namespace using ID
The following
update-private-dns-namespaceexample updates the description of a private DNS namespace using namespace ID.aws servicediscovery update-private-dns-namespace \ --idns-abcd1234xmpl5678\ --updater-request-idabcd1234-5678-90ab-cdef-xmpl12345678\ --namespace Description="The updated namespace description."Output:
{ "OperationId": "abcd1234-5678-90ab-cdef-xmpl12345678" }To confirm that the operation succeeded, you can run
get-operation.For more information, see AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
Example 2: To update a private DNS namespace using ARN
The following
update-private-dns-namespaceexample updates a private DNS namespace using its ARN.aws servicediscovery update-private-dns-namespace \ --idarn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678\ --updater-request-idabcd1234-5678-90ab-cdef-xmpl12345678\ --namespace Description="The updated namespace description."Output:
{ "OperationId": "abcd1234-5678-90ab-cdef-xmpl12345678" }For more information, see AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see UpdatePrivateDnsNamespace
in AWS CLI Command Reference.
-
The following code example shows how to use update-public-dns-namespace.
- AWS CLI
-
Example 1: To update a public DNS namespace using ID
The following
update-public-dns-namespaceexample updates the description of a public DNS namespace using its ID.aws servicediscovery update-public-dns-namespace \ --idns-abcd1234xmpl5678\ --updater-request-idabcd1234-5678-90ab-cdef-xmpl12345678\ --namespace Description="The updated namespace description."Output:
{ "OperationId": "abcd1234-5678-90ab-cdef-xmpl12345678" }To confirm that the operation succeeded, you can run
get-operation.For more information, see AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
Example 2: To update a public DNS namespace using ARN
The following
update-public-dns-namespaceexample updates a public DNS namespace using its ARN.aws servicediscovery update-public-dns-namespace \ --idarn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678\ --updater-request-idabcd1234-5678-90ab-cdef-xmpl12345678\ --namespace Description="The updated namespace description."Output:
{ "OperationId": "abcd1234-5678-90ab-cdef-xmpl12345678" }For more information, see AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see UpdatePublicDnsNamespace
in AWS CLI Command Reference.
-
The following code example shows how to use update-service-attributes.
- AWS CLI
-
Example 1: To update a service to add an attribute
The following
update-service-attributesexample updates the specified service to add a service attribute with a keyPortand a value80.aws servicediscovery update-service-attributes \ --service-idsrv-abcd1234xmpl5678\ --attributesPort=80This command produces no output.
For more information, see AWS Cloud Map services in the AWS Cloud Map Developer Guide.
Example 2: To update a service attributes using ARN
The following
update-service-attributesexample updates a service using its ARN to add a service attribute. Specifying the ARN is necessary for adding attributes to services created in namespaces shared with your account.aws servicediscovery update-service-attributes \ --service-idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678\ --attributesPort=80This command produces no output.
For more information, see AWS Cloud Map services and Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see UpdateServiceAttributes
in AWS CLI Command Reference.
-
The following code example shows how to use update-service.
- AWS CLI
-
Example 1: To update a service
The following
update-serviceexample updates a service to update theDnsConfigandHealthCheckConfigsettings.aws servicediscovery update-service \ --idsrv-abcd1234xmpl5678\ --service"DnsConfig={DnsRecords=[{Type=A,TTL=60}]},HealthCheckConfig={Type=HTTP,ResourcePath=/,FailureThreshold=2}"Output:
{ "OperationId": "abcd1234-5678-90ab-cdef-xmpl12345678" }To confirm that the operation succeeded, you can run
get-operation.For more information about updating a service, see Updating an AWS Cloud Map service in the AWS Cloud Map Developer Guide.
Example 2: To update a service using ARN
The following
update-serviceexample updates a service using its ARN. Specifying an ARN is necessary for services that are created in namespaces shared with your account.aws servicediscovery update-service \ --idarn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678\ --service"DnsConfig={DnsRecords=[{Type=A,TTL=60}]},HealthCheckConfig={Type=HTTP,ResourcePath=/,FailureThreshold=2}"Output:
{ "OperationId": "abcd1234-5678-90ab-cdef-xmpl12345678" }For more information about updating a service, see Updating an AWS Cloud Map service and Shared AWS Cloud Map namespaces in the AWS Cloud Map Developer Guide.
-
For API details, see UpdateService
in AWS CLI Command Reference.
-