Reputation: 11
The Use case that I am executing is:
The main purpose of waiting is:
I am invoking the Lambda function from shell script (shellScript.sh), and the command to invoke is in below code which is from AWS documentation.
In the Lambda function I have following python code to create an EC2 instance first and then detect whether an EC2 is running along with 2/2 status check, but it exits and return 200 success code to shell script when "instance state" shows running (Lambda still continues with other commands to run after that which are not mentioned here and EC2 status is in Initializing state).
Which API function should I use to block until EC2 "status check" show "2/2 checks passed"? (I don't want my Lambda function to exit until the status shows 2/2 checks passed.)
Note: Print response gives the status of 'ok'
I referred to Stack overflow link below and tried those options (as seen in my code below) but it didn't work for me.
How to block until EC2 status check is passed using Python Boto3?
ShellScript.sh:
aws lambda invoke --invocation-type RequestResponse --function-name <my-function-name> --payload '{"Key": "'$value'"}' /dev/stdout
Lambda_function.py:
instance = EC2.run_instances(
ImageId=<image-id>,
InstanceType=<instance-type>,
MinCount=1,
MaxCount=1,
.......
)
instance_id = instance['Instances'][0]['InstanceId']
ec2instance = ec2.Instance(id=instance_id)
ec2instance.wait_until_running()
waiter = EC2.get_waiter('instance_status_ok')
waiter.wait(
InstanceIds=[instance_id],
WaiterConfig={
'Delay': 15,
'MaxAttempts': 40
},
IncludeAllInstances = True
)
response = EC2.describe_instance_status(
InstanceIds=[instance_id],
IncludeAllInstances=True
)
print(response)
Upvotes: 1
Views: 2828
Reputation: 1
boto3 wait_until_running doesn't work as desired
@ UNH Intern,
Try the attached link and see if it is help in your case
Upvotes: -1