AWS code-library documentation change
Summary
Updated AWS Cloud Map CLI examples to include ARN usage patterns, cross-account namespace sharing documentation, and standardized resource identifiers across all examples
Security assessment
Changes demonstrate secure practices for cross-account resource management through ARN usage and owner-account parameters, but do not address specific vulnerabilities. Added documentation about resource ownership tracking (ResourceOwner/CreatedByAccount fields) and shared namespace security considerations
Diff
diff --git a/code-library/latest/ug/cli_2_servicediscovery_code_examples.md b/code-library/latest/ug/cli_2_servicediscovery_code_examples.md index 717c9b29c..0df06123e 100644 --- a//code-library/latest/ug/cli_2_servicediscovery_code_examples.md +++ b//code-library/latest/ug/cli_2_servicediscovery_code_examples.md @@ -125 +125 @@ The following code example shows how to use `create-service`. -**To create a service** +**Example 1: To create a service using namespace ID** @@ -133 +133 @@ The following `create-service` example creates a service. - --dns-config "NamespaceId=ns-ylexjili4cdxy3xm,RoutingPolicy=MULTIVALUE,DnsRecords=[{Type=A,TTL=60}]" + --dns-config "RoutingPolicy=MULTIVALUE,DnsRecords=[{Type=A,TTL=60}]" @@ -141,2 +141,3 @@ Output: - "Id": "srv-p5zdwlg5uvvzjita", - "Arn": "arn:aws:servicediscovery:us-west-2:803642222207:service/srv-p5zdwlg5uvvzjita", + "Id": "srv-abcd1234xmpl5678", + "Arn": "arn:aws:servicediscovery:us-west-2:123456789012:service/srv-abcd1234xmpl5678", + "ResourceOwner": "123456789012", @@ -144 +145,41 @@ Output: - "NamespaceId": "ns-ylexjili4cdxy3xm", + "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](https://docs.aws.amazon.com/cloud-map/latest/dg/creating-services.html) 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-id arn: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", @@ -146 +187 @@ Output: - "NamespaceId": "ns-ylexjili4cdxy3xm", + "NamespaceId": "ns-abcd1234xmpl5678", @@ -155,2 +196,4 @@ Output: - "CreateDate": 1587081768.334, - "CreatorRequestId": "567c1193-6b00-4308-bd57-ad38a8822d25" + "Type": "DNS_HTTP", + "CreateDate": "2025-08-18T13:45:31.023000-05:00", + "CreatorRequestId": "abcd1234-5678-90ab-cdef-xmpl12345678", + "CreatedByAccount": "123456789012" @@ -160 +203 @@ Output: -For more information, see [Creating services](https://docs.aws.amazon.com/cloud-map/latest/dg/creating-services.html) in the _AWS Cloud Map Developer Guide_. +For more information, see [Shared AWS Cloud Map namespaces](https://docs.aws.amazon.com/cloud-map/latest/dg/sharing-namespaces.html) in the _AWS Cloud Map Developer Guide_. @@ -172 +215 @@ The following code example shows how to use `delete-namespace`. -**To delete a namespace** +**Example 1: To delete a namespace** @@ -178 +221 @@ The following `delete-namespace` example deletes a namespace. - --id ns-ylexjili4cdxy3xm + --id ns-abcd1234xmpl5678 @@ -185 +228 @@ Output: - "OperationId": "gv4g5meo7ndmeh4fqskygvk23d2fijwa-k98y6drk" + "OperationId": "abcd1234-5678-90ab-cdef-xmpl12345678" @@ -190 +233,19 @@ To confirm that the operation succeeded, you can run `get-operation`. For more i -For more information, see [Deleting namespaces](https://docs.aws.amazon.com/cloud-map/latest/dg/deleting-namespaces.html) in the _AWS Cloud Map Developer Guide_. +For more information, see [Deleting an AWS Cloud Map namespace](https://docs.aws.amazon.com/cloud-map/latest/dg/deleting-namespaces.html) 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](https://docs.aws.amazon.com/cloud-map/latest/dg/deleting-namespaces.html) in the _AWS Cloud Map Developer Guide_. @@ -202 +263 @@ The following code example shows how to use `delete-service-attributes`. -**To delete a service attribute** +**Example 1: To delete a service attribute** @@ -208 +269 @@ The following `delete-service-attributes` example deletes a service attribute wi - --service-id srv-e4anhexample0004 \ + --service-id srv-abcd1234xmpl5678 \ @@ -214 +275,15 @@ This command produces no output. -For more information, see [Deleting namespaces](https://docs.aws.amazon.com/cloud-map/latest/dg/deleting-namespaces.html) in the _AWS Cloud Map Developer Guide_. +For more information, see [AWS Cloud Map services](https://docs.aws.amazon.com/cloud-map/latest/dg/working-with-services.html) 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 \ + --attributes Port + + +This command produces no output. + +For more information, see [AWS Cloud Map services](https://docs.aws.amazon.com/cloud-map/latest/dg/working-with-services.html) and [Shared AWS Cloud Map namespaces](https://docs.aws.amazon.com/cloud-map/latest/dg/sharing-namespaces.html) in the _AWS Cloud Map Developer Guide_. @@ -226 +301 @@ The following code example shows how to use `delete-service`. -**To delete a service** +**Example 1: To delete a service** @@ -232 +307,14 @@ The following `delete-service` example deletes a service. - --id srv-p5zdwlg5uvvzjita + --id srv-abcd1234xmpl5678 + + +This command produces no output. + +For more information, see [Deleting an AWS Cloud Map service](https://docs.aws.amazon.com/cloud-map/latest/dg/deleting-services.html) 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 @@ -237 +325 @@ This command produces no output. -For more information, see [Deleting services](https://docs.aws.amazon.com/cloud-map/latest/dg/deleting-services.html) in the _AWS Cloud Map Developer Guide_. +For more information, see [Deleting an AWS Cloud Map service](https://docs.aws.amazon.com/cloud-map/latest/dg/deleting-services.html) in the _AWS Cloud Map Developer Guide_. @@ -249 +337 @@ The following code example shows how to use `deregister-instance`. -**To deregister a service instance** +**Example 1: To deregister a service instance** @@ -269,0 +358,19 @@ For more information, see [Deregistering service instances](https://docs.aws.ama +**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-id web-server-01 + + +Output: + + + { + "OperationId": "gv4g5meo7ndmkqjrhpn39wk42xmpl" + } + +For more information, see [Shared AWS Cloud Map namespaces](https://docs.aws.amazon.com/cloud-map/latest/dg/sharing-namespaces.html) and [Deregistering an AWS Cloud Map service instance](https://docs.aws.amazon.com/cloud-map/latest/dg/deregistering-instances.html) in the _AWS Cloud Map Developer Guide_. + @@ -280 +387 @@ The following code example shows how to use `discover-instances-revision`. -**To discover the revision of an instance** +**Example 1: To discover the revision of an instance** @@ -298,0 +406,20 @@ For more information, see [AWS Cloud Map service instances](https://docs.aws.ama +**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-name shared-service \ + --owner-account 123456789111 + + +Output: + + + { + "InstancesRevision": 1234567890 + } + +For more information, see [Shared AWS Cloud Map namespaces](https://docs.aws.amazon.com/cloud-map/latest/dg/sharing-namespaces.html) and [AWS Cloud Map service instances](https://docs.aws.amazon.com/cloud-map/latest/dg/working-with-instances.html) in the _AWS Cloud Map Developer Guide_. + @@ -309 +436 @@ The following code example shows how to use `discover-instances`. -**To discover registered instances** +**Example 1: To discover registered instances** @@ -336 +463,2 @@ Output: - ] + ],