Skip to content

Commit

Permalink
Fix resilient service region (#5489)
Browse files Browse the repository at this point in the history
* Use EC2 instance metadata to get the region instead of passing in a hardcoded value.

* Use branch version of server.py for testing.

* Get server script from main.

* Remove region from spec.
  • Loading branch information
Laren-AWS authored and ford-at-aws committed Dec 15, 2023
1 parent 291f853 commit d35cc66
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/cross_service/resilient_service/auto_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def replace_instance_profile(
inst_ready = True
self.ssm_client.send_command(
InstanceIds=[instance_id], DocumentName='AWS-RunShellScript',
Parameters={'commands': ['cd / && sudo python3 server.py 80 us-west-2']})
Parameters={'commands': ['cd / && sudo python3 server.py 80']})
log.info("Restarted the Python web server on instance %s.", instance_id)
except ClientError as err:
raise AutoScalerError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def run():
"""
parser = argparse.ArgumentParser()
parser.add_argument('port', default=80, type=int, help="The port where the HTTP server listens.")
parser.add_argument('region', default='us-west-2', help="The AWS Region of AWS resources used by this example.")
parser.add_argument('--region', default=ec2_metadata.region, help="The AWS Region of AWS resources used by this example.")
args = parser.parse_args()

server_port = args.port
Expand Down
2 changes: 1 addition & 1 deletion workflows/resilient_service/SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ Select an instance, replace its instance profile, and reboot the instance.
self.ssm_client.send_command(
InstanceIds=[instance_id],
DocumentName='AWS-RunShellScript',
Parameters={'commands': ['cd / && sudo python3 server.py 80 us-west-2']})
Parameters={'commands': ['cd / && sudo python3 server.py 80']})
```

Tell the user all about it:
Expand Down
2 changes: 1 addition & 1 deletion workflows/resilient_service/resources/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def run():
"""
parser = argparse.ArgumentParser()
parser.add_argument('port', default=80, type=int, help="The port where the HTTP server listens.")
parser.add_argument('region', default='us-west-2', help="The AWS Region of AWS resources used by this example.")
parser.add_argument('--region', default=ec2_metadata.region, help="The AWS Region of AWS resources used by this example.")
args = parser.parse_args()

server_port = args.port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ sleep 30 # prevent "Error: Rpmdb changed underneath us"
yum install python-pip -y
python3 -m pip install boto3 ec2-metadata
wget -O server.py https://raw.githubusercontent.com/awsdocs/aws-doc-sdk-examples/main/workflows/resilient_service/resources/server.py
python3 server.py 80 us-west-2
python3 server.py 80

0 comments on commit d35cc66

Please sign in to comment.