---
updatedAt: 2026-03-02T11:13:26.000Z
---

# Amazon Connect - Call Authentication - Python

# Pre-requisites

1. First Orion Branded Communications agreement
2. Access to First Orion Customer Portal
3. Vetted and Approved Business
4. Ability to originate phone calls from configured phone numbers in calling platform
5. Understanding of current calling platform and environment to integrate required API

# Generate First Orion API Keys

Check out this guide for API Credentials - [Guide Link](https://developer.firstorion.com/firstorion-public/docs/api-credentials)

# Lambda Setup

### Lambda Directory and Code

1. Create a local directory with this lambda\_function.py file inside. Later, this will be the Lambda zip folder that's uploaded.
2. If needed, change the a\_number and b\_number variables in the code to correspond to the payload from your input source.
   * This example is being used by Amazon Connect. Connect documentation: [doc link](https://docs.aws.amazon.com/connect/latest/adminguide/connect-lambda-functions.html)

```python Amazon Connect Example
# lambda_function.py

import json
import requests
import os

def lambda_handler(event, context):
  
    a_number = event["Details"]["ContactData"]["SystemEndpoint"]["Address"] # Phone number making the call.
    b_number = event["Details"]["ContactData"]["CustomerEndpoint"]["Address"] # Phone number being called.

    # For your logging processes.
    print("aNumber: " + a_number);
    
    # Makes the pre-call push.
    precall = push_precall(a_number,b_number)
    # Log pre-call push
    print("Pre-call Status: " +str(precall["statusCode"])) 
    print("Pre-call Message: " +precall["body"])
    
    return (precall)
    
def get_token():
    api_key = os.environ['API_KEY'] # API Key set in enviroment variables.
    secret_key = os.environ['SECRET_KEY'] # Secret Key set in enviroment variables.

    url = "https://api.firstorion.com/v1/auth"
    
    headers = {
      'X-SERVICE': 'auth',
      'content-type': 'application/json',
      'X-API-KEY': api_key,
      'X-SECRET-KEY': secret_key
    }
    
    response = requests.request("POST", url, headers=headers)
    data = response.json()
    return data['token']

    
def push_precall(a_number,b_number):
    token = get_token()
    url = "https://api.firstorion.com/exchange/v1/calls/push"
    
    payload = json.dumps({
      "aNumber": a_number,
      "bNumber": b_number
    })
    headers = {
      'Authorization': token,
      'Content-Type': 'application/json'
    }
    
    response = requests.request("POST", url, headers=headers, data=payload)
    data = response.json()
    
    value = {
        'statusCode': response.status_code,
        'body': data['body']['message']
    }
    
    # Return JSON Object
    return json.loads(json.dumps(value))
```
```python Generic Numbers Example
# lambda_function.py

...
def lambda_handler(event, context):
  
    a_number = "+15555555555" # Phone number making the call.
    b_number = "+15554444444" # Phone number being called.
...
```

<br />

### Lambda Code Libraries

This Lambda requires the requests library to be included in the Lambda directory. Here is a method to include that library.

1. Navigate to the directory containing the lambda\_funciton.py file.

2. Open this directory in a terminal and run the following. This should create the necessary library folders.
   ```curl
   pip install requests -t ./
   ```

3. Compress/ZIP those folders with the lambda code from inside the folder. This will be uploaded to the Lambda

[block:image]{"images":[{"image":["https://files.readme.io/83cf0855ba16b8569b4ee1dfac31f4b33ba2ba0b8c5b5612ef5fcffb9db9af0e-compress_lambda_files.png","",""],"align":"center"}]}[/block]

<br />

## Lambda Creation

#### 1. Create the Lambda

Environment Information

* Function Runtime: Python3.13
* Architecture: x86\_64

#### 2. Upload Lambda Zip

* This is the compressed folder from above

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/52b6b1a0ed44da146a415a2871a62e61b36f9b3ef23bee997ab07476b4a68fec-LambdaZipUpload.png",
        "",
        ""
      ],
      "align": "center"
    }
  ]
}
[/block]

#### 3. Add API Keys to Lambda Environment Variables

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/edb7e7caebced406658e3d9d4d58ba3407c91300299b6690874cb25a9193a6cf-LambdaEnvVariables.png",
        "",
        ""
      ],
      "align": "center"
    }
  ]
}
[/block]

<br />

# Using the Lambda

Change the a\_number and b\_number variables in the code to correspond to the payload from your input source.

* This example is being used by Amazon Connect. Connect documentation: [doc link](https://docs.aws.amazon.com/connect/latest/adminguide/connect-lambda-functions.html)

```python Amazon Connect Example
# lambda_function.py

...
def lambda_handler(event, context):
  
    a_number = event["Details"]["ContactData"]["SystemEndpoint"]["Address"] # Phone number making the call.
    b_number = event["Details"]["ContactData"]["CustomerEndpoint"]["Address"] # Phone number being called.
...
```
```python Generic Numbers Example
# lambda_function.py

...
def lambda_handler(event, context):
  
    a_number = "+15555555555" # Phone number making the call.
    b_number = "+15554444444" # Phone number being called.
...
```

* Example Amazon Connect Outbound Whisper Flow. Make sure to place the Invoke AWS Lambda function block before the Call phone number block, this will make sure the Call Auth API call happens before the phone call.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/6a46482dc433dcf850b8d699409493960613b8e71f289046862216e3c01cc4e7-CallAuthFlow.png",
        "",
        ""
      ],
      "align": "center"
    }
  ]
}
[/block]

* Full Outbound Whisper Flow example.

![](https://files.readme.io/aa6886f9215783f8894e09b2fc328d85f1990fc902e49f2bf686eb55d2fa8607-image.png)