Registering a resource as an AWS Cloud Map service
instance
You can register your application's resources as instances in a AWS Cloud Map service. For example,
assume you've created a service called users
for all application resources that
manage user data. You can then register a DynamoDB table that's used to store user data as an
instance in this service.
The following features are not available on the AWS Cloud Map console:
-
When you register a service instance using the console, you can't create an alias
record that routes traffic to an Elastic Load Balancing (ELB) load balancer. When you register an instance,
you must include the AWS_ALIAS_DNS_NAME
attribute. For more information, see
RegisterInstance in the AWS Cloud Map API Reference.
-
If you register an instance using a service that includes a custom health check, you
can't specify the initial status for the custom health check. By default, the initial
status of a custom health checks is Healthy. If you want the initial
health status to be Unhealthy, register the instance programmatically
and include the AWS_INIT_HEALTH_STATUS
attribute. For more information, see
RegisterInstance in the AWS Cloud Map API Reference.
To register an instance in a service, follow these steps.
- AWS Management Console
-
Sign in to the AWS Management Console and open the AWS Cloud Map console at https://console.aws.amazon.com/cloudmap/.
-
In the navigation pane, choose Namespaces.
-
On the Namespaces page, choose the namespace that contains
the service that you want to use as a template for registering a service
instance.
-
On the Namespace: namespace-name
page, choose the service that you want to use.
-
On the Service: service-name
page,
choose Register service instance.
-
On the Register service instance page, choose an
Instance type. Depending on the namespace instance discovery
configuration, you can choose to specify an IP address, an Amazon EC2 instance ID, or other
identifying information for a resource that doesn't have an IP address.
You can choose EC2 instance only in HTTP namespaces.
-
For Service instance ID, provide an identifier associated
with the service instance.
If you want to update an existing instance, provide the
identifier associated with the instance you want to update. Then, use the next steps to update values
and reregister the instance.
-
Based on your choice of Instance type, perform the following
steps.
You can't use the AWS_
prefix (not case sensitive) in a key when you specify a custom attribute.
Instance type |
Steps |
IP address
|
-
Under Standard attributes, for IPv4
address, provide an IPv4 address, if any, where your
application can access the resource that's associated with this service
instance.
-
For IPv6 address, provide an IPv6 IP address,
if any, where your applications can access the resource that's
associated with this service instance.
-
For Port, specify any port your application
must include to access the resource that's associated with this service
instance. Port is required when the service
includes an SRV record or an Amazon RouteĀ 53 health check.
-
(Optional) Under Custom attributes, specify any
key-value pairs you want to associate with the resource.
|
EC2 instance |
-
For EC2 instance ID, select the ID of the Amazon EC2
instance that you want to register as a AWS Cloud Map service instance.
-
(Optional) Under Custom attributes, specify any
key-value pairs you want to associate with the resource.
|
Identifying information for another resource |
-
Under Standard attributes, if the service
configuration includes a CNAME DNS record, you'll
see a CNAME field. For CNAME,
specify the domain name that you want RouteĀ 53 to return in response to DNS
queries (for example, example.com ).
-
Under Custom attributes, specify any
identifying information for a resource that isn't an IP address or an
Amazon EC2 instance ID as a key-value pair. For example, you can register a
Lambda function by specifying a key called function and
providing the name of the Lambda function as a value. You can also
specify a key called name and provide a name that you can
use for programmatic instance discovery.
|
-
Choose Register service instance.
- AWS CLI
-
-
When you submit a RegisterInstance
request:
-
For each DNS record that you define in the service that's specified by
ServiceId
, a record is created or updated in the hosted zone that's
associated with the corresponding namespace.
-
If the service includes HealthCheckConfig
, a health check is
created based on the settings in the health check configuration.
-
Any health checks are associated with each of the new or updated
records.
Register a service instance with the register-instance
command (replace the
red
values with your own).
aws servicediscovery register-instance \
--service-id srv-xxxxxxxxx
\
--instance-id myservice-xx
\
--attributes=AWS_INSTANCE_IPV4=172.2.1.3,AWS_INSTANCE_PORT=808
- AWS SDK for Python (Boto3)
-
-
If you don't already have Boto3
installed, you can find instructions
for installing, configuring, and using Boto3
here.
-
Import Boto3
and use servicediscovery
as your
service.
import boto3
client = boto3.client('servicediscovery')
-
When you submit a RegisterInstance
request:
-
For each DNS record that you define in the service that's specified by
ServiceId
, a record is created or updated in the hosted zone that's
associated with the corresponding namespace.
-
If the service includes HealthCheckConfig
, a health check is
created based on the settings in the health check configuration.
-
Any health checks are associated with each of the new or updated
records.
Register a service instance with register_instance()
(replace the
red
values with your own).
response = client.register_instance(
Attributes={
'AWS_INSTANCE_IPV4': '172.2.1.3',
'AWS_INSTANCE_PORT': '808',
},
InstanceId='myservice-xx
',
ServiceId='srv-xxxxxxxxx
',
)
# If you want to see the response
print(response)
Example response output
{
'OperationId': '4yejorelbukcjzpnr6tlmrghsjwpngf4-k95yg2u7',
'ResponseMetadata': {
'...': '...',
},
}