cloud:aws:servicediscovery
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
cloud:aws:servicediscovery [2023/11/01 07:13] – removed - external edit (Unknown date) 127.0.0.1 | cloud:aws:servicediscovery [2023/11/01 07:13] (current) – ↷ Page moved from business_process_management:camunda:cloud:aws:servicediscovery to cloud:aws:servicediscovery skipidar | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ==== Service Discovery ==== | ||
+ | |||
+ | |||
+ | Examples | ||
+ | |||
+ | Add service | ||
+ | <sxh shell> | ||
+ | #/bin/bash -e | ||
+ | |||
+ | #stop on error | ||
+ | #set -e | ||
+ | |||
+ | |||
+ | |||
+ | ######## ARGUMENTS | ||
+ | |||
+ | |||
+ | # retrieve the ec2 instance ID: i-0d39e398760299ce0 | ||
+ | instanceId=${1? | ||
+ | |||
+ | # retrieve the private ip of the instance: 10.142.251.149 | ||
+ | instancePrivateIp=${2? | ||
+ | |||
+ | # retrieve name of the building: zurich-klinik | ||
+ | buildingName=${3? | ||
+ | |||
+ | # retrieve the vpc id: vpc-00aeb2af06257ebf8 | ||
+ | vpcid=${4? | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ########## SCRIPT START | ||
+ | |||
+ | dnsnamespace=" | ||
+ | servicename=" | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | aws servicediscovery create-private-dns-namespace --name $dnsnamespace --vpc $vpcid | ||
+ | |||
+ | # retrieve the namespace id | ||
+ | namespaceId=$(aws servicediscovery list-namespaces --query " | ||
+ | echo " | ||
+ | |||
+ | |||
+ | # ignore errors, when service already exists | ||
+ | aws servicediscovery create-service --name $servicename \ | ||
+ | | ||
+ | |||
+ | |||
+ | # retrieve the service id | ||
+ | serviceId=$(aws servicediscovery list-services --query " | ||
+ | echo " | ||
+ | |||
+ | |||
+ | aws servicediscovery register-instance --service-id $serviceId \ | ||
+ | --instance-id $instanceId | ||
+ | |||
+ | |||
+ | # ping the service | ||
+ | echo -e " | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | Remove service | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | <sxh shell> | ||
+ | #/bin/bash -e | ||
+ | |||
+ | # Removes the services and the namespace, if no instances are available in the service anymore | ||
+ | |||
+ | |||
+ | #stop on error | ||
+ | #set -e | ||
+ | |||
+ | |||
+ | ######## ARGUMENTS | ||
+ | |||
+ | |||
+ | # retrieve the building ID: zurich-klinik | ||
+ | buildingName=${1? | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ########## SCRIPT START | ||
+ | |||
+ | |||
+ | dnsnamespace=" | ||
+ | servicename=" | ||
+ | |||
+ | |||
+ | |||
+ | # get the instance id by service | ||
+ | serviceId=$(aws servicediscovery list-services --query " | ||
+ | echo " | ||
+ | |||
+ | # get the instace id by service | ||
+ | instanceId=$(aws servicediscovery list-instances --service-id $serviceId --query " | ||
+ | echo " | ||
+ | |||
+ | # retrieve the namespace id | ||
+ | namespaceId=$(aws servicediscovery list-namespaces --query " | ||
+ | echo " | ||
+ | |||
+ | # deregister the instance | ||
+ | aws servicediscovery deregister-instance --service-id $serviceId --instance-id $instanceId | ||
+ | |||
+ | # deregister the service, will only work if no instances are left | ||
+ | aws servicediscovery delete-service --id $serviceId | ||
+ | |||
+ | # deregister the namespace, will only work if no services | ||
+ | aws servicediscovery delete-namespace --id $namespaceId | ||
+ | |||
+ | |||
+ | |||
+ | # ping the service | ||
+ | echo -e " | ||
+ | |||
+ | </ | ||