There are more AWS SDK examples available in the AWS Doc SDK Examples
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-namespace
example creates an HTTP namespaceexample.com
.aws servicediscovery create-http-namespace \ --name
example.com
\ --creator-request-idexample-request-id
Output:
{ "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-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 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-namespace
example creates an public DNS namespaceexample.com
.aws servicediscovery create-public-dns-namespace \ --name
example-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-service
example creates a service.aws servicediscovery create-service \ --name
myservice
\ --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-service
example 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 \ --name
myservice-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-namespace
example deletes a namespace.aws servicediscovery delete-namespace \ --id
ns-abcd1234xmpl5678
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 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-namespace
example deletes a namespace using its ARN.aws servicediscovery delete-namespace \ --id
arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678
Output:
{ "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-attributes
example deletes a service attribute with the keyPort
that is associated with the specified service.aws servicediscovery delete-service-attributes \ --service-id
srv-abcd1234xmpl5678
\ --attributesPort
This 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-attributes
example 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-id
arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678
\ --attributesPort
This 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-service
example deletes a service.aws servicediscovery delete-service \ --id
srv-abcd1234xmpl5678
This 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-service
example deletes a service using its ARN.aws servicediscovery delete-service \ --id
arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678
This 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-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 AWS Cloud Map Developer Guide.
Example 2: To deregister a service instance using service ARN for shared namespaces
The following
deregister-instance
example 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-id
arn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjita
\ --instance-idweb-server-01
Output:
{ "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-revision
example discovers the increasing revision of an instance.aws servicediscovery discover-instances-revision \ --namespace-name
example.com
\ --service-namemyservice
Output:
{ "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-revision
example 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-name
shared-namespace
\ --service-nameshared-service
\ --owner-account123456789111
Output:
{ "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-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" } } ], "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-instances
example 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-name
shared-namespace
\ --service-nameshared-service
\ --owner-account123456789111
Output:
{ "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-instance
example gets the attributes of a service.aws servicediscovery get-instance \ --service-id
srv-e4anhexample0004
--instance-idi-abcd1234
Output:
{ "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-instance
example 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 account123456789111
in a namespace owned by account123456789012
.aws servicediscovery get-instance \ --service-id
arn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjita
\ --instance-idweb-server-01
Output:
{ "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-status
example gets the health status of instances associated with the specified service.aws servicediscovery get-instances-health-status \ --service-id
srv-e4anhexample0004
Output:
{ "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-status
example 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-id
arn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjita
Output:
{ "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-namespace
example retrieves information about the specified namespace.aws servicediscovery get-namespace \ --id
ns-abcd1234xmpl5678
Output:
{ "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-namespace
example 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 \ --id
arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-abcd1234xmpl5678
Output:
{ "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-operation
example gets the result of a namespace creation operation.aws servicediscovery get-operation \ --operation-id
abcd1234xmpl5678abcd1234xmpl5678-abcd1234
Output:
{ "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-operation
example 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-id
abcd1234xmpl5678abcd1234xmpl5678-abcd1234
\ --owner-account123456789111
Output:
{ "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-attributes
example gets the attributes of a service.aws servicediscovery get-service-attributes \ --service-id
srv-abcd1234xmpl5678
Output:
{ "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-attributes
example 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-id
arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678
Output:
{ "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-service
example gets the settings of a specified service.aws servicediscovery get-service \ --id
srv-abcd1234xmpl5678
Output:
{ "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-service
example 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 account123456789111
created the service in a namespace shared by account123456789012
.aws servicediscovery get-service \ --id
arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678
Output:
{ "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-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" }, "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-instances
example 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-id
arn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjita
Output:
{ "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-namespaces
example lists namespaces.aws servicediscovery list-namespaces
Output:
{ "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-namespaces
example lists namespaces that are shared with the caller account by other AWS accounts using theRESOURCE_OWNER
filter.aws servicediscovery list-namespaces \ --filters
Name=RESOURCE_OWNER,Values=OTHER_ACCOUNTS,Condition=EQ
Output:
{ "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-operations
example lists operations that have a status ofPENDING
orSUCCESS
.aws servicediscovery list-operations \ --service-id
srv-e4anhexample0004
\ --filtersName=STATUS,Condition=IN,Values=PENDING,SUCCESS
Output:
{ "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-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 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-services
example lists services that are created in namespaces shared with the caller account123456789012
by other AWS accounts using theRESOURCE_OWNER
filter.aws servicediscovery list-services \ --filters
Name=RESOURCE_OWNER,Values=OTHER_ACCOUNTS,Condition=EQ
Output:
{ "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-resource
example lists tags for the specified resource.aws servicediscovery list-tags-for-resource \ --resource-arn
arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-e4anhexample0004
Output:
{ "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-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 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-instance
example 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-id
arn: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-resource
example associates aDepartment
tag with the valueEngineering
with the specified namespace.aws servicediscovery tag-resource \ --resource-arn
arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-e4anhexample0004
\ --tagsKey=Department,
Value=Engineering
This 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-resource
example removes aDepartment
tag from the specified namespace.aws servicediscovery untag-resource \ --resource-arn
arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-e4anhexample0004
\ --tagsKey=Department,
Value=Engineering
This 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-namespace
example updates the specified HTTP namespace's description.aws servicediscovery update-http-namespace \ --id
ns-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-namespace
example updates the specified HTTP namespace using its ARN.aws servicediscovery update-http-namespace \ --id
arn: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-status
example 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-id
srv-e4anhexample0004
\ --instance-idexample
\ --statusHEALTHY
This 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-status
example 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-id
arn:aws:servicediscovery:us-west-2:123456789012:service/srv-p5zdwlg5uvvzjita
\ --instance-idweb-server-01
\ --statusHEALTHY
This 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-namespace
example updates the description of a private DNS namespace using namespace ID.aws servicediscovery update-private-dns-namespace \ --id
ns-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-namespace
example updates a private DNS namespace using its ARN.aws servicediscovery update-private-dns-namespace \ --id
arn: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-namespace
example updates the description of a public DNS namespace using its ID.aws servicediscovery update-public-dns-namespace \ --id
ns-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-namespace
example updates a public DNS namespace using its ARN.aws servicediscovery update-public-dns-namespace \ --id
arn: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-attributes
example updates the specified service to add a service attribute with a keyPort
and a value80
.aws servicediscovery update-service-attributes \ --service-id
srv-abcd1234xmpl5678
\ --attributesPort=80
This 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-attributes
example 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-id
arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678
\ --attributesPort=80
This 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-service
example updates a service to update theDnsConfig
andHealthCheckConfig
settings.aws servicediscovery update-service \ --id
srv-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-service
example 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 \ --id
arn: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.
-