Ejemplo n.º 1
0
def contact(event, context):
    tag_event("custom-tag", "contact-form", {"custom": {"tag": "data "}})

    print(event)
    data = json.loads(event.get("body"))
    full_name, email = data.get("FullName"), data.get("Email")
    subject, message = data.get("Subject"), data.get("Message")

    mailer.send_email(
        Source=SENDER,
        Destination={"ToAddresses": [RECEIVER]},
        Message={
            "Subject": {"Data": f"[Site] {subject}", "Charset": "utf-8"},
            "Body": {
                "Text": {
                    "Data": "Message from: {}, email: {}:\n---\n{}".format(
                        full_name, email, message
                    ),
                    "Charset": "utf-8",
                }
            },
        },
    )

    headers = {
        "Access-Control-Allow-Origin": "*",
    }

    body = {
        "message": "Thank you for your email",
    }

    response = {"statusCode": 200, "headers": headers, "body": json.dumps(body)}

    return response
Ejemplo n.º 2
0
def sentiment(event, context):
    tag_event(SERVERLESS_TAG_1, SERVERLESS_TAG_2)
    phrase = get_query_params(event)
    headers = {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": True
    }

    status_code = STATUS_CODE_SUCCESS

    try:
        body = run(phrase)
    except Exception as exc:
        if not body:
            body = {"error": str(exc)}
            status_code = STATUS_CODE_FAILED
        else:
            status_code = STATUS_CODE_PART

    response = {
        "statusCode": status_code,
        "headers": headers,
        "body": json.dumps(body)
    }

    return response
Ejemplo n.º 3
0
def register(payload):
    resp = requests.post(
        f"{BASE_URL}/register",
        auth=HTTPBasicAuth(os.environ.get("AUTH_USERNAME"),
                           os.environ.get("AUTH_PASSWORD")),
        json=payload,
    )
    tag_event("eslworks_register_status", resp.status_code)
    resp.raise_for_status()
    return resp
Ejemplo n.º 4
0
def handle_registration(event, context):
    tag_event("registration", "raw_event", event)

    form_data = json.loads(event["body"])
    payload = build_registration_payload(form_data["data"])

    tag_event("registration", "computed_payload", payload)

    register(payload)

    return {"statusCode": 200}
Ejemplo n.º 5
0
def hello(event, context):
    tag_event('custom-tag', 'hello-world', {'custom': {'tag': 'data '}})

    headers = {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": True
    }

    body = {
        "message": "This is just a test message as a response",
        "input": event
    }

    response = {
        "statusCode": 200,
        "headers": headers,
        "body": json.dumps(body)
    }

    return response
Ejemplo n.º 6
0
def hello(event, context):
    tag_event('custom-tag', 'hello-world', {'custom': {'tag': 'data '}})

    headers = {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": True
    }

    body = {
        "message": "Go Serverless v1.0! Your function executed successfully!",
        "input": event
    }

    response = {
        "statusCode": 200,
        "headers": headers,
        "body": json.dumps(body)
    }

    return response

    # Use this code if you don't use the http event with the LAMBDA-PROXY
    # integration
    """
Ejemplo n.º 7
0
def event_tags(event, context):
    tag_event('event-tagged', 'true', {
        'customerId': 5,
        'userName': '******'
    })
    return 'success'
Ejemplo n.º 8
0
def get_customer(customer_id):
    tag_event('customer_id', customer_id, {'more': 'data', 'with': 'the tag'})
    return customers.get(customer_id)