from utils import http_error_handling, invoke import json import boto3 from fleece.xray import monkey_patch_botocore_for_xray import os monkey_patch_botocore_for_xray() def get_lc_instance_type(client, lc_name): desc = client.describe_launch_configurations( LaunchConfigurationNames=[lc_name] ) if not len(desc['LaunchConfigurations']): raise Exception('LC %s not found' % lc_name) lc = desc['LaunchConfigurations'][0] used_instance_type = lc['InstanceType'] print("%s uses instance type %s" % (lc_name, used_instance_type)) return used_instance_type def find_subnets_to_exclude(unavailable, used, asg, subnet_to_az): unavailable_azs = unavailable[used] subnets_to_exclude = [] for subnet in asg['subnets']: subnet_az = subnet_to_az[subnet] if subnet_az in unavailable_azs: subnets_to_exclude.append(subnet) return subnets_to_exclude
import boto3, json, logging, argparse, time, os,requests, uuid from fleece.xray import (monkey_patch_botocore_for_xray, monkey_patch_requests_for_xray, trace_xray_subsegment) monkey_patch_botocore_for_xray() monkey_patch_requests_for_xray() '''Setup cd imageProc deactivate virtualenv fleece_venv --python=python3 source fleece_env/bin/activate pip install fleece cd .. python setupApps.py -f setupIProc.json --no_spotwrap --turn_on_tracing --profile aws_profile //go to DynamoDB Management Console and create table imageLables with key "id" of type string //create a table triggerTable with key "name" of type string //go to s3 Management Console and create bucket MYBKTNAME //create a folder called imgProc and place any image (filename.jpg) in this folder test locally via: python imageProc/imageProc.py MYBKTNAME imgProc filename.jpg //go to Lambda Management Console for //ImageProcPy, Triggers tab, add Trigger, S3, choose bucket MYBKTNAME, //prefix: imgProc, enable trigger test as function via: aws lambda invoke --invocation-type Event --function-name ImageProcPy --region us-west-2 --profile aws_profile --payload '{"eventSource":"ext:invokeCLI","name":"MYBKTNAME","key":"imgProc/filname.jpg"}' outputfile test as triggered function by dropping another file into MYBKTNAME/imageProc/ folder. See entry in DynamoDB table imageLabels See entry in DynamoDB table triggerTable (make this table trigger a different function) View X-Ray service graph (there will be two "applications" with separate "clients" without GammaRay support)