This project contains an AWS CloudFormation custom resource that manages Amazon Connect contact flows. and a Python script that exports existing contact flows from Connect into a CloudFormation template that references the custom resource.
- The AWS CLI
- The AWS Serverless Application Model must be installed
- Python 3.7
- Node 12.x
CloudFormation does not natively support creating an Amazon Connect contact flow. CFNCreateContactFlow is a custom resource that enables you to create and update contact flows using CloudFormation.
Connect does not support deleting contact flows.
CloudFormation does not natively support attaching a Lambda to Amazon Connect. CFNLambdaConnectPermission is a custom resource that enables you to use CloudFormation to attach a Lambda to a Connect instance.
Connect does not support deleting contact flows.
From the command line, run the following commands. This will deploy an AWS Lambda custom resource that can be called by your CloudFormation template.
sam build -t cfn-contact-flow-custom-resources .yml
sam deploy --template-file .aws-sam/build/template.yaml --stack-name cfn-contact-flow-custom-resources --capabilities "CAPABILITY_NAMED_IAM" --resolve-s3
AWSTemplateFormatVersion: '2010-09-09'
Description: Connect Contact Flows
Resources:
sample:
Type: Custom::ConnectContactFlow
Properties:
ServiceToken: !ImportValue: CFNCreateContactFlow
Description: A sample contact flow
Content: '{stringified JSON content}'
Type: CONTACT_FLOW
Tags: {}
InstanceId:
Ref: ConnectInstanceID
Name: sample
Note: The custom resource supports the contact flow format returned from the describe-contact-flow AWS CLI or the various SDK's. This format is different from the one that is exported from the web console.
You can use the script described below to export a CloudFormation template from an existing Connect Instance.
If you have items in a source Connect instance that you want to import into a destination Connect Instance, you can use the create-contact-flow-template Python script.
First create a config.json file in the create contact flow directory:
{
"Input":{
"ConnectInstanceId":"<Your connect instance ID>"
},
"ResourceFilters":
{
"ContactFlows":["test1","test2"]
},
"Output":{
"Filename": "contact-flows.json",
"TemplateDescription":"Connect Contact Flows"
}
}
- ConnectInstanceId -- the ID of the Connect instance containing your contact flows
- ContactFlows - The exporter will export any published contact flows where the name contains one of the listed words
- Filename - The name of the output CloudFormation template.
- TemplateDescription - Describes the purpose of the stack.
Then run the script:
cd create-contact-flow
pip3 install -r requirements.txt #First time only
python3 create-contact-flow-template.py
Once you run the script, a CloudFormation template will be created.
The template requires one parameter, ConnectInstanceId, which should be the instance where you want to create your contact flows.
- Replaces the source account number with the ${AWS::AccountId}
- Replaces the source Connect Instance Id with ${ConnectInstanceID}
- Replaces references in TransferToFlow to the correct destination references
CFNConnectAssociateLambda is a custom resource used to associate a Lambda to a Connect instance.
GetContactLambdaPermission:
Type: Custom::ConnecctAssociateLambda
Properties:
InstanceId: !Ref ConnectInstanceID
FunctionArn: !GetAtt SampleLambda.Arn
ServiceToken: !ImportValue CFNConnectAssociateLambda
See CONTRIBUTING for more information.