Skip to content

Commit b1567ef

Browse files
author
Yuriy Bezsonov
committed
update lambda launcher
1 parent de4bb0c commit b1567ef

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

infrastructure/cdk/src/main/java/com/unicorn/constructs/VSCodeIde.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ public VSCodeIde(final Construct scope, final String id, final VSCodeIdeProps pr
292292
"ec2:TerminateInstances",
293293
"ec2:CreateTags",
294294
"ec2:DescribeInstances",
295+
"ec2:DescribeInstanceStatus",
295296
"ec2:DescribeSubnets"
296297
))
297298
.build());

infrastructure/cdk/src/main/resources/instance-launcher.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ def lambda_handler(event, context):
7575
instance_id = response['Instances'][0]['InstanceId']
7676
print(f'Successfully launched instance {instance_id} ({instance_type} in {subnet_id})')
7777

78+
# Wait for instance to reach running state before returning
79+
print(f'Waiting for instance {instance_id} to reach running state...')
80+
waiter = ec2.get_waiter('instance_running')
81+
waiter.wait(
82+
InstanceIds=[instance_id],
83+
WaiterConfig={
84+
'Delay': 10,
85+
'MaxAttempts': 30 # 30 * 10 = 300 seconds (5 minutes) max wait
86+
}
87+
)
88+
print(f'Instance {instance_id} is now running')
89+
7890
responseData = {
7991
'InstanceId': instance_id,
8092
'InstanceType': instance_type,

0 commit comments

Comments
 (0)