This repository showcases an integration for syncing transcript record deletion between AWS Amazon Connect and Salesforce Service Cloud Voice.
The process involves placing an event trigger on a Lambda function, which, when a corresponding S3 .wav
recording is deleted after 90 days, triggers the Lambda to make a REST callout to an Apex endpoint.
The Apex side then handles the deletion of all ConversationEntry records related to that recording.
-
Deploy Components to Salesforce Org:
- CLI:
sf project deploy start --target-org <sf_org>
- CLI:
-
Create a New API_Only User:
User License
:Salesforce
Profile
:API_ONLY
-
Verify User and Set Up Password:
- Save the username and password for later use.
-
Assign Permissions:
- Assign the user the
Delete_Transcripts_REST
permission set.
- Assign the user the
-
Navigate to Connected App Setup:
Setup
->App Manager
->New Connected App
-
Fill Out App Details:
App Name
,API Name
, andContact Email
-
Enable OAuth Settings:
- Set Callback URL to
https://login.salesforce.com/services/oauth2/callback
- Add OAuth scopes:
Manager user data via APIs (api)
,Perform requests at any time (refresh_token, offline_access)
- Set Callback URL to
-
Save Consumer Details:
- After initialization, click
Manage Consumer Details
:- Save the
Consumer Key
andConsumer Secret
for later use.
- Save the
- After initialization, click
-
Add API_Only Profile to Connected App:
- After creating the connected app, navigate back to
App Manager
- Navigate to the newly created app and click
Manage
Profiles
->Manage Profiles
- Add
API_Only
and save
- After creating the connected app, navigate back to
- Create IAM Policy:
- Create a new
IAM Policy
with the required permissions.
- Create a new
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:PutLogEvents",
"logs:CreateLogGroup",
"logs:CreateLogStream"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::*/*"
}
]
}
-
Create IAM Role:
- Navigate to
IAM Console
->Roles
->Create Role
- Select
AWS Service
andLambda
as the entity and use cases. - Add the previously created policy.
- Create the role.
- Navigate to
-
Create Lambda Function:
- Navigate to
Lambda Console
->Functions
-> Create a new function inNode.js 20.x
runtime andx86_64
architecture. - Use the role created in step 2.
- Navigate to
-
Add S3 Trigger:
- Add a new trigger for S3 source, specifying object deletion events with
.wav
suffix.
- Add a new trigger for S3 source, specifying object deletion events with
-
Deploy Function Code:
- Add the source code from
./aws/lambda/
and deploy the function.
- Add the source code from
-
Add Environment Variables:
CONSUMER_KEY
: Consumer key saved from the connected appPRIVATE_KEY
: Consumer secret saved from the connected appUSERNAME
: Username for a user in the SF org with permissions to run the delete jobPASSWORD
: Password for a user in the SF org with permissions to run the delete jobSF_AUTH_ENDPOINT
:https://test.salesforce.com/services/oauth2/token
for a sandbox environment,https://login.salesforce.com/services/oauth2/token?
for a production environmentREST_API_ENDPOINT
:<sf_org_domain>/services/apexrest/DeleteTranscript
-
Add Test Event:
- Add a test event with the provided JSON, replacing placeholders
BUCKET_NAME
andEXAMPLE_FILE
.
- Add a test event with the provided JSON, replacing placeholders
{
"Records": [
{
"eventVersion": "2.0",
"eventSource": "aws:s3",
"awsRegion": "us-east-1",
"eventTime": "1970-01-01T00:00:00.000Z",
"eventName": "ObjectRemoved:Delete",
"userIdentity": {
"principalId": "EXAMPLE"
},
"requestParameters": {
"sourceIPAddress": "127.0.0.1"
},
"responseElements": {
"x-amz-request-id": "EXAMPLE123456789",
"x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "testConfigRule",
"bucket": {
"name": "BUCKET_NAME",
"ownerIdentity": {
"principalId": "EXAMPLE"
},
"arn": "arn:aws:s3:::BUCKET_NAME"
},
"object": {
"key": "EXAMPLE_FILE.wav",
"size": 1024,
"eTag": "e13fd810551be669677d4c3f8558e78d",
"sequencer": "0A1B2C3D4E5F678901"
}
}
}
]
}
-
Navigate to S3 Bucket:
- AWS Console -> Desired S3 Bucket
-
Create Lifecycle Rule:
- Under
Management
tab ->Lifecycle Rules
->Create lifecycle rule
- Configure rule settings, specifying the desired expiration period.
- For Versioned Buckets, also checkmark
Permanently delete noncurrent versions of objects
- The following image from a versioned bucket depicts a lifecycle rule that expires objects after 90 days and permanently deletes them 1 day after expiration.
- Under
-
Configure Event Notification:
- Under
Properties
tab ->Event Notifications
, edit the event notification publishing to the Lambda function. - Under
Lifecycle
, checkmarkDelete marker added by Lifecycle for a versioned object
.
- Under
-
Save Changes.