in setup/fleetLauncherApp/fleetLauncherLambda/app.py [0:0]
def lambda_handler(event, context):
# Set base parameters for each simulation job. Order from Lambda event, then environment variables.
if 'simulationJobParams' in event:
if 'vpcConfig' in event['simulationJobParams']:
sim_job_params['vpcConfig'] = sim_job_params['vpcConfig']
if 'iamRole' in event['simulationJobParams']:
sim_job_params['iamRole'] = sim_job_params['iamRole']
if 'outputLocation' in event['simulationJobParams']:
sim_job_params['outputLocation'] = sim_job_params['outputLocation']
if 'simulationApplicationArn' in event:
app_arn = event['simulationApplicationArn']
if 'serverIP' in event:
private_ip = event['serverIP']
else:
# Launch Server.
server_app_params = create_application_config(event['server'], True, 'localhost')
server_job_params = deepcopy(sim_job_params)
server_job_params['simulationApplications'].append(server_app_params)
server_job_response = robomaker.create_simulation_job(
iamRole=server_job_params["iamRole"],
maxJobDurationInSeconds=server_job_params["maxJobDurationInSeconds"],
simulationApplications=[server_app_params],
vpcConfig=server_job_params["vpcConfig"],
loggingConfig=server_job_params["loggingConfig"],
outputLocation=server_job_params["outputLocation"]
)
# Wait for server to be available.
waiter_name = 'SimJobCreated'
waiter_model = WaiterModel(waiter_config)
custom_waiter = create_waiter_with_client(waiter_name, waiter_model, robomaker)
custom_waiter.wait(job=server_job_response['arn'])
desc_result = robomaker.describe_simulation_job( job = server_job_response['arn'] )
private_ip = desc_result['networkInterface']['privateIpAddress']
# Launch multiple robot batches.
batch_job_requests = []
client_app_params = {}
client_job_params = {}
for robot in event['robots']:
client_app_params[robot['name']] = create_application_config(robot, False, private_ip)
client_job_params[robot['name']] = deepcopy(sim_job_params)
client_job_params[robot['name']]['simulationApplications'].append(client_app_params[robot['name']])
batch_job_requests.append(client_job_params[robot['name']])
response = robomaker.start_simulation_job_batch(
batchPolicy={
'timeoutInSeconds': DEFAULT_MAX_DURATION,
'maxConcurrency': len(event['robots'])
},
createSimulationJobRequests=batch_job_requests,
tags = {
'launcher': 'multi_robot_fleet'
})
return {
'statusCode': 200,
'body': response['arn']
}