Amazon Connect - Call Authentication
Introduction
This document describes the integration between Amazon Connect and Hiya Secure Branding to provide branded outbound call experiences. The integration ensures that before each outbound call, Amazon Connect invokes a Lambda function, which communicates with the Hiya Secure Branding API to register the call details.
High-level workflow:
- Amazon Connect invokes an AWS Lambda at the start of the Outbound Whisper Flow, before any Play prompt, so it runs before each outbound call is dialed.
- The Lambda function retrieves API credentials from AWS Secrets Manager.
- Lambda constructs and sends a request to the Hiya Secure Branding REST API.

Choose your integration
This guide provides two Lambda functions. Pick the one that matches how you use Hiya:
- Enterprise: you own the calling numbers and announce your own calls. The Lambda calls
POST /v1/originatorswith your business's API key. - Partner: you announce calls on behalf of businesses you manage. The Lambda calls
POST /partner/v1/businesses/{businessId}/call-authentication/pre-announcewith your partner API key. See the Partner Call Authentication API.
All other sections apply to both. Differences are called out inline.
Prerequisites
- An operational Amazon Connect instance, and ability to originate phone calls from it.
- Outbound call flow customization permissions in Connect.
Enterprise:
- Access to Hiya Connect Portal.
- Vetted and approved business.
- Hiya Secure Branding API credentials (
enterprise-app-idandenterprise-app-secret) from a production API key. Test keys are rejected with401on this endpoint.
Partner:
- A partner account with call authentication enabled. Contact Hiya to enable it.
- The businesses you manage and their calling numbers onboarded through the Partner Management APIs, with Secure Branding active.
- Your partner API credentials (
partner-app-idandpartner-app-secret), the same API key you use for the Partner Management APIs. Use a production key; test keys are rejected.
Setting up Hiya Connect Portal
Enterprise: check out this guide to learn how to set up your Hiya Connect Portal for secure branded calling, and how to get access to API keys: Secure Your Branded Call from Spoofers
Partner: onboard businesses and numbers through the Partner Management APIs instead.
Storing API Credentials in AWS Secrets Manager
The Hiya Secure Branding API requires authentication using credentials issued by Hiya.
These should be securely stored in AWS Secrets Manager.
Store the keys for your integration in a single secret named ConnectCC_Secure_Branding. Enterprise integrations store enterprise-app-id and enterprise-app-secret; partner integrations store partner-app-id and partner-app-secret:
| Secret key | Maps to API field | Example |
|---|---|---|
enterprise-app-id | username portion of auth | PROD_24b...J7m |
enterprise-app-secret | password portion of auth | z4b...UA |
partner-app-id | username portion of auth | PROD_24b...J7m |
partner-app-secret | password portion of auth | z4b...UA |
Enterprise: enterprise-app-id and enterprise-app-secret are your business's API key. Hiya identifies your business from it, so no business ID is needed.
Partner: partner-app-id and partner-app-secret are your partner API key. The business is passed per call as a Lambda input parameter (see Integrating with Amazon Connect Call Flow), not stored in the secret.
Configuring the AWS Lambda Function
The Lambda function is responsible for:
- Retrieving credentials from Secrets Manager.
- Building the request body with call metadata.
- Authenticating and calling the Hiya API.
- Handling failures without exceeding timeout. If Hiya is unreachable, the call proceeds rather than being blocked
Dependencies
This function is written in Node.js and makes use of the following dependency:
@aws-sdk/client-secrets-manager(AWS SDK for JavaScript v3).axios: https://www.npmjs.com/package/axios
Note: axios is not part of the Lambda runtime, so it must be included in the deployment package. The Node.js runtimes include the AWS SDK v3, but AWS recommends bundling the SDK version you tested with. For production, build a deployment package or use AWS SAM/Serverless Framework/Lambda Layers to package the function together with these libraries.
Example Lambda Implementation
Below is a reference implementation for each integration. Both use the same dependencies, secret, timeouts, and fail-open behaviour.
Enterprise
// index.mjs — Node.js 24.x, ESM
import axios from "axios";
import {
SecretsManagerClient,
GetSecretValueCommand,
} from "@aws-sdk/client-secrets-manager";
// Hiya Secure Branding API — outbound call registration endpoint.
const HIYA_API_ENDPOINT = "https://api.hiyaapi.com/v1/originators";
// Name of the Secrets Manager secret holding enterprise-app-id and enterprise-app-secret.
const SECRET_NAME = process.env.HIYA_SECRET_NAME || "ConnectCC_Secure_Branding";
// How long Hiya should treat this call's branding info as valid.
const TIME_TO_LIVE_SECONDS = 15;
const smClient = new SecretsManagerClient({});
// Cache the secret across warm Lambda invocations so repeat calls skip the Secrets Manager round trip.
let cachedSecret;
async function getSecret() {
if (cachedSecret) return cachedSecret;
const resp = await smClient.send(
new GetSecretValueCommand({ SecretId: SECRET_NAME })
);
cachedSecret = JSON.parse(resp.SecretString);
return cachedSecret;
}
export const handler = async (event) => {
// Amazon Connect passes call metadata to the Lambda under event.Details.ContactData.
// SystemEndpoint = Connect's outbound number; CustomerEndpoint = the number being called.
const originatingPhone = event.Details.ContactData.SystemEndpoint?.Address;
const terminatingPhone = event.Details.ContactData.CustomerEndpoint?.Address;
const callReason = event.Details.Parameters?.callReason;
try {
// 1. Retrieve Hiya credentials from Secrets Manager.
const secret = await getSecret();
// 2. Build the Basic Auth header: base64("enterprise-app-id:enterprise-app-secret").
const authHeader =
"Basic " +
Buffer.from(`${secret["enterprise-app-id"]}:${secret["enterprise-app-secret"]}`).toString("base64");
// 3. Build the request payload from Connect's call metadata.
const payload = {
originatingPhone,
terminatingPhone,
timeToLiveSeconds: TIME_TO_LIVE_SECONDS,
...(callReason !== undefined && { callReason }),
};
// 4. Announce the call to Hiya
const response = await axios.post(HIYA_API_ENDPOINT, payload, {
headers: { Authorization: authHeader, "Content-Type": "application/json" },
timeout: 3000,
});
// 5. Success (200 or 202) — the call flow can proceed to place the outbound call.
// Connect only accepts string values in the returned object.
return { status: "REGISTERED", httpStatus: String(response.status) };
} catch (err) {
// 6. If Hiya is unreachable or returns an error,
// the call proceeds unbranded rather than being blocked (fail-open).
console.error("Hiya registration failed:", err.message, JSON.stringify(err.response?.data));
return { status: "FAILED_OPEN" };
}
};
Partner
The partner Lambda reads the Hiya ID of the business from the businessId input parameter of the Connect "AWS Lambda function" block. If it is missing, the function does not call Hiya and returns FAILED_OPEN.
// index.mjs — Node.js 24.x, ESM
import axios from "axios";
import {
SecretsManagerClient,
GetSecretValueCommand,
} from "@aws-sdk/client-secrets-manager";
// Hiya Partner Call Authentication API — pre-announce endpoint, per managed business.
const HIYA_API_BASE = "https://api.hiyaapi.com/partner/v1/businesses";
// Name of the Secrets Manager secret holding partner-app-id and partner-app-secret.
const SECRET_NAME = process.env.HIYA_SECRET_NAME || "ConnectCC_Secure_Branding";
// How long Hiya should treat this call's branding info as valid.
const TIME_TO_LIVE_SECONDS = 15;
const smClient = new SecretsManagerClient({});
// Cache the secret across warm Lambda invocations so repeat calls skip the Secrets Manager round trip.
let cachedSecret;
async function getSecret() {
if (cachedSecret) return cachedSecret;
const resp = await smClient.send(
new GetSecretValueCommand({ SecretId: SECRET_NAME })
);
cachedSecret = JSON.parse(resp.SecretString);
return cachedSecret;
}
export const handler = async (event) => {
// Amazon Connect passes call metadata to the Lambda under event.Details.ContactData.
// SystemEndpoint = Connect's outbound number; CustomerEndpoint = the number being called.
const originatingPhone = event.Details.ContactData.SystemEndpoint?.Address;
const terminatingPhone = event.Details.ContactData.CustomerEndpoint?.Address;
const contactId = event.Details.ContactData.ContactId;
// businessId and callReason are input parameters set on the Connect "AWS Lambda function" block.
const businessId = event.Details.Parameters?.businessId;
const callReason = event.Details.Parameters?.callReason;
if (!businessId) {
console.error("Hiya registration skipped: no businessId parameter");
return { status: "FAILED_OPEN" };
}
try {
// 1. Retrieve Hiya partner credentials from Secrets Manager.
const secret = await getSecret();
// 2. Build the Basic Auth header: base64("partner-app-id:partner-app-secret").
const authHeader =
"Basic " +
Buffer.from(`${secret["partner-app-id"]}:${secret["partner-app-secret"]}`).toString("base64");
// 3. Build the request payload from Connect's call metadata.
// callTracingInfo is stored with the announcement as-is.
const payload = {
originatingPhone,
terminatingPhone,
timeToLiveSeconds: TIME_TO_LIVE_SECONDS,
...(callReason !== undefined && { callReason }),
callTracingInfo: { connectContactId: contactId },
};
// 4. Announce the call to Hiya on behalf of the business.
const url = `${HIYA_API_BASE}/${encodeURIComponent(businessId)}/call-authentication/pre-announce`;
const response = await axios.post(url, payload, {
headers: { Authorization: authHeader, "Content-Type": "application/json" },
timeout: 3000,
});
// 5. Success (200 or 202) — the call flow can proceed to place the outbound call.
// Connect only accepts string values in the returned object.
return { status: "REGISTERED", httpStatus: String(response.status) };
} catch (err) {
// 6. If Hiya is unreachable or returns an error,
// the call proceeds unbranded rather than being blocked (fail-open).
// The error body includes a requestId to quote when contacting Hiya.
console.error("Hiya registration failed:", err.message, JSON.stringify(err.response?.data));
return { status: "FAILED_OPEN" };
}
};
Request Body to Hiya API
Enterprise
The enterprise Lambda constructs the request payload with the following parameters:
| Parameter | Required | Format | Description |
|---|---|---|---|
terminatingPhone | Yes | E.164, e.g. +14155551234 | Customer phone number being called. |
timeToLiveSeconds | Yes | integer | Expiration time for call branding info. |
originatingPhone | Yes | E.164 | Caller phone number (Connect's outbound number). Must be registered to your Hiya Connect account with Secure Branding enabled, otherwise the request returns 401. |
callReason | Optional | string, max 50 characters | Reason for the call, shown to the called party. Must exactly match a call reason approved for this account in the Connect console. Longer than 50 characters returns 400. A value that does not match an approved reason is not rejected, but the call is branded with no call reason (the static call reason is suppressed too). An empty string suppresses the call reason. If omitted, the static call reason configured for the number is used. |
The API responds with:
200: the announcement was stored.202: it was partially stored. Both count as success.503: the announcement was not stored.400: invalid request.401: invalid or test credentials, or anoriginatingPhonenot enrolled in Secure Branding.
axios rejects any non-2xx status, so the example returns REGISTERED for 200/202 and FAILED_OPEN for everything else.
For detailed explanation, see the current Hiya API reference for the outbound call registration endpoint: Announce outbound call
Partner
The partner Lambda calls POST https://api.hiyaapi.com/partner/v1/businesses/{businessId}/call-authentication/pre-announce with the following parameters:
| Parameter | Required | Format | Description |
|---|---|---|---|
businessId (path) | Yes | UUID | Hiya ID of the business you are announcing for, from the businessId Lambda input parameter. Not a UUID returns 400. Not one of your businesses, or call authentication not enabled for your account, returns 404. |
terminatingPhone | Yes | E.164, e.g. +14155551234 | Customer phone number being called. |
timeToLiveSeconds | Yes | integer | Expiration time for call branding info. |
originatingPhone | Yes | E.164 | Caller phone number (Connect's outbound number). Must be registered to that business with Secure Branding active, otherwise the request returns 401. |
callReason | Optional | string, max 50 characters | Reason for the call, shown to the called party only if it exactly matches a call reason approved for the business. Longer than 50 characters returns 400. A value that does not match an approved reason is accepted, but the call is branded with no call reason (the static call reason is suppressed too). An empty string shows no reason. If omitted, the static call reason configured for the number is used. |
callTracingInfo | Optional | flat object | Metadata stored with the announcement. Values must be strings, numbers, or booleans. The example sends the Connect contact ID. |
The API responds with:
200: the announcement was stored.202: it was partially stored. Both count as success.503: the announcement was not stored.500: an error on Hiya's side.400: invalid request.401: invalid or test credentials, or anoriginatingPhonenot registered to the business with Secure Branding active.404: the business is not yours, or call authentication is not enabled for your account.
Error responses are JSON with requestId, timestamp, and errors (each with code and message). The example logs the body; quote the requestId when contacting Hiya.
For details, see the API reference for Pre-announce a call.
Creating the Lambda Function
The code and permissions above assume the function already exists. Here's how to actually create and deploy it.
1. Package the deployment artifact
Since axios is not in the Lambda runtime and AWS recommends bundling the SDK, build the deployment package locally:
mkdir hiya-secure-branding && cd hiya-secure-branding
npm init -y
npm install axios @aws-sdk/client-secrets-manager
# save the handler code above as index.mjs in this folder
zip -r function.zip index.mjs node_modules package.json
2. Create the IAM execution role
Before creating the function, create the role it will run as. Attach a policy allowing:
secretsmanager:GetSecretValue, scoped to the specific secret's ARN (not a wildcard resource).- CloudWatch logging permissions (
logs:CreateLogGroup,logs:CreateLogStream,logs:PutLogEvents). kms:Decrypton the key, if the secret is encrypted with a customer-managed KMS key.
3. Create the function
In the Lambda console: Create function → Author from scratch.
- Function name: e.g.
ConnectCC_Outbound_Hiya - Runtime: Node.js 24.x
- Architecture: x86_64 (or arm64, if your build targets it)
- Permissions: choose "Use an existing role" and select the role created in step 2.
4. Upload the code
Under Code source, choose Upload from → .zip file and upload function.zip from step 1. Set the Handler to index.handler — Lambda resolves this against index.mjs's exported handler function regardless of the .mjs extension.
5. Set environment variables
Under Configuration → Environment variables, add:
| Key | Value |
|---|---|
HIYA_SECRET_NAME | The name of your Secrets Manager secret (e.g. ConnectCC_Secure_Branding) |
6. Set the function timeout
Under Configuration → General configuration, set Timeout to a small value — 5 seconds is a reasonable ceiling, well clear of Connect's 8-second hard limit but generous relative to the 3-second axios timeout in the code. Don't default this to the maximum; see the note on Connect's 8-second ceiling under Integrating with Amazon Connect Call Flow.
7. Grant Amazon Connect permission to invoke it
This is separate from the execution role above — it controls who's allowed to call the function, not what the function itself can access. In the Amazon Connect console, go to your instance → Flows tab → add the function under Lambda functions. If the function is in the same Region as the Connect instance, this automatically adds the required resource-based policy to the Lambda allowing your Connect instance to invoke it.
If the function is in a different Region, add the permission yourself. --region is the Lambda's Region:
aws lambda add-permission \
--region <lambda-region> \
--function-name ConnectCC_Outbound_Hiya \
--statement-id AllowConnectInvoke \
--action lambda:InvokeFunction \
--principal connect.amazonaws.com \
--source-account <account-id> \
--source-arn arn:aws:connect:<connect-region>:<account-id>:instance/<instance-id>
8. Test before wiring it into a call flow
Use the Lambda console's Test tab with an event shaped like what Connect sends, so you can confirm the function runs end-to-end before it's live on a real outbound call. Replace SystemEndpoint.Address with your real originating number enrolled in Secure Branding; any other number returns 401:
{
"Details": {
"ContactData": {
"SystemEndpoint": { "Address": "+14155559999" },
"CustomerEndpoint": { "Address": "+14155551234" }
},
"Parameters": {
"callReason": "Appointment reminder"
}
}
}
For the partner Lambda, also pass the business's Hiya ID and, optionally, a contact ID. The originating number must be registered to that business:
{
"Details": {
"ContactData": {
"ContactId": "test-contact-1",
"SystemEndpoint": { "Address": "+14155559999" },
"CustomerEndpoint": { "Address": "+14155551234" }
},
"Parameters": {
"businessId": "9b8a1c4e-2c0f-4f3d-9a1e-7b3a2b4c6d8f",
"callReason": "Appointment reminder"
}
}
}
A successful test should return {"status": "REGISTERED", "httpStatus": "200"} (or FAILED_OPEN if the request fails; the HTTP status and Hiya's response body are in the function's CloudWatch logs). Never log the axios error object itself: it contains the request's Authorization header, which is your Base64-encoded API key.
Integrating with Amazon Connect Call Flow
To ensure that every outbound call triggers the Hiya API, modify your Connect Outbound Whisper Flow:
- Open your Amazon Connect instance in the AWS console.
- Edit the outbound whisper flow used for your agent-initiated outbound calls (or create a new one) — this is distinct from the main contact flow.
- At the start of the flow, add an "AWS Lambda function" block positioned before any "Play prompt" block. Blocks before the first Play prompt run before the call is dialed, so branding registration completes before the call is placed.
- Select the Lambda function created earlier. To send a call reason, add a function input parameter
callReason. For the partner Lambda, also add a function input parameterbusinessIdwith the Hiya ID of the business, either as a static value or from a contact attribute (for example, set per flow or queue). - Set invocation to Synchronous mode. Set the Lambda's own timeout to a small value — a few seconds at most — rather than approaching Connect's maximum.
- Route the block's Error branch onward to the call, the same as Success. Lambda timeouts and failures take the Error branch, so without this the call does not fail open.
Caution: the "Call Phone Number" block sets the caller ID; it does not place the call. originatingPhone must be the caller ID actually presented to the called party. If you override the caller ID, make sure the Lambda sends that number.
