import json import boto3 import logging import os import urllib import m2c2_metrics as metrics import m2c2_globals as var import m2c2_utils as utils logger = logging.getLogger() logger.setLevel(logging.INFO) # AWS Resource and clients iot_client = boto3.client('iot-data', config=utils.get_boto_config()) def to_user(name, version, type, message): user_message = {} if name == "": topic = "m2c2/job/" + type else: topic = "m2c2/job/" + name + "/" + type user_message["job-name"] = name if version != "": user_message["version"] = version user_message["message"] = message logger.info("User message: " + str(user_message)) iot_client.publish(topic=topic, qos=1, payload=json.dumps(user_message))
from datetime import datetime import logging import os import json import m2c2_post_handler as post import m2c2_utils as utils import m2c2_globals as var import m2c2_job_builder_main import m2c2_s3_handler as s3 logger = logging.getLogger() logger.setLevel(logging.INFO) # AWS Resource and clients ddb_client = boto3.resource('dynamodb', config=utils.get_boto_config()) ddb_table = ddb_client.Table(os.environ["JOB_DYNAMODB_TABLE"]) def valid_job_request(job_name): global job_in_ddb job_in_ddb = read_ddb_jobid(job_name) return 1 # This functions retrieves all ddb job entries for a given job name def read_ddb_jobid(job_name): try: return ddb_table.query( KeyConditionExpression=Key("jobid").eq(job_name))
import boto3 import os import logging import m2c2_post_handler as post import m2c2_utils as utils import m2c2_globals as var import m2c2_ddb_handler as ddb import m2c2_job_builder_main logger = logging.getLogger() logger.setLevel(logging.INFO) # AWS Resource and clients s3_client = boto3.resource('s3', config=utils.get_boto_config()) def write(user_job_request, type): job_name = utils.get_metadata("name", user_job_request, 0) job_version = utils.get_metadata("version", user_job_request, 0) job_protocol = utils.get_metadata("protocol", user_job_request, 0) try: s3object = s3_client.Object( os.environ["JOB_BUILDER_BUCKET"], job_protocol + "-" + os.environ["JOB_BUILDER_KEY"] + job_name + "#v" + job_version + "." + type) s3object.put( Body=(bytes(json.dumps(user_job_request).encode('UTF-8')))) except Exception as err: logger.info("s3 write traceback:" + str(err))
import json import time import m2c2_protocol_converter as builder import m2c2_utils as utils import m2c2_globals as var import m2c2_post_handler as post logger = logging.getLogger() logger.setLevel(logging.INFO) aws_region = os.environ['AWS_REGION'] # AWS Resource and clients lambda_client = boto3.client('lambda', config=utils.get_boto_config()) gg_client = boto3.client('greengrass', config=utils.get_boto_config()) class generate_greengrass_resources: def __init__(self, user_request): self.job_name = utils.get_metadata("name", user_request, 0) self.job_version = utils.get_metadata("version", user_request, 0) self.protocol = utils.get_metadata("protocol", user_request, 0) self.process = utils.get_metadata("process", user_request, 0) self.sitename = utils.get_metadata("site-name", user_request, 0) self.area = utils.get_metadata("area", user_request, 0) self.machinename = utils.get_metadata("machine-name", user_request, 0) self.lambda_role = os.environ["CONNECTOR_LAMBDA_ROLE"] self.m2c2_local_resource_path = var.m2c2_local_resource_path