

# CloudFormation template reference

The template is for Salesforce. To connect another system, add it to the gateway the stack creates; see [Add the system to the gateway](real-time-data-integration-rest.md#real-time-data-integration-resources-other).


**What the stack creates**  

| Resource | Created by | 
| --- | --- | 
| Integration user and API credentials (Step 2) | You, in Salesforce | 
| Token refresh function, which gets a Salesforce access token with your consumer secret every five minutes and stores it in a token secret, and the API key credential provider in AgentCore Identity that sends that token on every call | Stack | 
| Gateway, with your instance's Discovery URL, protocol version and its own ID in **Allowed audiences** | Stack. A step that runs during deployment sets the audience, because a CloudFormation resource can't refer to its own ID. | 
| Salesforce target, `salesforce`, as an OpenAPI target, and, when **Custom operations file (S3 URI)** is set, a second OpenAPI target, `salesforce-custom`, with your own operations | Stack | 
| Registration of the gateway with your instance | Stack | 
| Change alerts for the gateway, target, credential provider, token secret, token refresh function and registration | Stack | 
| Health dashboard (`{{stack-name}}-{{region}}-health`) and four alarms: tool calls failing, Salesforce API allowance, token refresh, and Run As user changed | Stack | 
| Account and case guide: inbound flow, guide flow, wrap-up flow when **Wrap-up flow and form** is `Enabled`, nine flow modules (Find the record, Find the customer, Read the account, Read a case, List the account's cases, Create a case, Create a customer, Update a record and Read the verified account), and two nested stacks: `{{stack-name}}-GuideViews-{{random}}`, with the guide's views, and `{{stack-name}}-GuideModules-{{random}}`, with the Create a case with details flow module | Stack | 
| The AI resources:+ the AI self-service flow and its Lex bot;<br />+ the knowledge agent, and the account agent when **Account agent for verified contacts** is `true`;<br />+ the agent assist AI agent;<br />+ two prompts, self-service and agent assist;<br />+ a security profile for each AI agent;<br />+ change alerts for the AI agents, prompts and the modules they run;<br />+ the knowledge base's association with the assistant, when **Knowledge base to associate (ARN)** is set;<br />+ when **Existing Connect assistant (ARN)** is empty, a Connect assistant and its association with your instance, which the stack keeps when it is deleted or its create fails. | Stack | 
| The assistant's **Self service** default and the AI agents' security profile associations | You, after each create or update | 
| Your own inbound flow (Step 4) | You | 

Use the gateway-only template if you build your own guide on the gateway; deploy it in the same way as in [Step 3: Deploy the CloudFormation stack](real-time-data-integration-resources.md). It asks only for the Connect Customer and Salesforce fields, and the optional custom operations file; it has no test queue, wrap-up, Find the record or AI self-service fields. Its default stack name is the same as the other template's, so use a different stack name if you already have a stack in the account and Region.


**Launch the gateway-only template**  

| Connect Customer Region of your instance | Template | 
| --- | --- | 
| US East (N. Virginia) (`us-east-1`) | [![Launch Stack in US East (N. Virginia)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration-gateway.template.json&stackName=connect-sf-real-time) | 
| US West (Oregon) (`us-west-2`) | [![Launch Stack in US West (Oregon)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration-gateway.template.json&stackName=connect-sf-real-time) | 
| Africa (Cape Town) (`af-south-1`) | Not available: neither the External Tool block nor Amazon Bedrock AgentCore Gateway is available in this Region. | 
| Asia Pacific (Seoul) (`ap-northeast-2`) | [![Launch Stack in Asia Pacific (Seoul)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-2#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration-gateway.template.json&stackName=connect-sf-real-time) | 
| Asia Pacific (Singapore) (`ap-southeast-1`) | [![Launch Stack in Asia Pacific (Singapore)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-1#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration-gateway.template.json&stackName=connect-sf-real-time) | 
| Asia Pacific (Sydney) (`ap-southeast-2`) | [![Launch Stack in Asia Pacific (Sydney)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-2#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration-gateway.template.json&stackName=connect-sf-real-time) | 
| Asia Pacific (Tokyo) (`ap-northeast-1`) | [![Launch Stack in Asia Pacific (Tokyo)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-1#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration-gateway.template.json&stackName=connect-sf-real-time) | 
| Canada (Central) (`ca-central-1`) | [![Launch Stack in Canada (Central)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=ca-central-1#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration-gateway.template.json&stackName=connect-sf-real-time) | 
| Europe (Frankfurt) (`eu-central-1`) | [![Launch Stack in Europe (Frankfurt)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=eu-central-1#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration-gateway.template.json&stackName=connect-sf-real-time) | 
| Europe (London) (`eu-west-2`) | [![Launch Stack in Europe (London)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=eu-west-2#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration-gateway.template.json&stackName=connect-sf-real-time) | 
| AWS GovCloud (US-West) (`us-gov-west-1`) | Not available: the External Tool block isn't available in this Region. | 


**Templates**  

| Template file | What it creates | 
| --- | --- | 
| `connect-sf-real-time-data-integration.template.json` | The template with the account and case guide: everything the gateway-only template creates, plus the account and case guide in your instance: the inbound flow, the guide flow, the wrap-up flow when `WrapUp` is `Enabled`, nine flow modules, and two nested stacks, which the stack reads from the release files: the guide's views and the Create a case with details flow module. It also creates the AI self-service flow with its AI agents. It deploys in the Regions that [Launch Stack by Region](#real-time-data-integration-launch-regions) lists. | 
| `connect-sf-real-time-data-integration-views.template.json` | The guide's 17 views (15 with `WrapUp` set to `Disabled`), which the template with the account and case guide creates as its nested stack `GuideViews`. You deploy it yourself only when you host the release files in your own bucket (`NestedTemplateBaseUrl`). | 
| `connect-sf-real-time-data-integration-modules.template.json` | The Create a case with details flow module, which the template with the account and case guide creates as its nested stack `GuideModules`. You stage it yourself only when you host the release files in your own bucket (`NestedTemplateBaseUrl`). | 
| `connect-sf-real-time-data-integration-gateway.template.json` | The gateway-only template: the gateway, the token refresh function and the credential provider that send your Salesforce access token, the Salesforce target, the registration of the gateway with your instance, the change alerts, and the health dashboard and the four alarms. | 

The templates have the following parameters. All of them are required except `SalesforceIntegrationUsername`, `CustomOperationsS3Uri`, `FindRecordModuleArn`, `ExistingAssistantArn`, `SelfServiceAccountTool`, `ConnectAssistantKnowledgeBaseArn`, `WrapUp` and `NestedTemplateBaseUrl`, which have defaults. "With guides" means only the template with the account and case guide.

The stack's name is part of each resource's name:
+ the gateway;
+ the credential provider, `{{stack-name}}-api-key`;
+ the token secret, `{{stack-name}}-token`;
+ the token refresh function, `{{stack-name}}-token-refresh`;
+ the integration in Connect Customer, `Salesforce - {{stack-name}}`;
+ the guide's flows and flow modules, `{{stack-name}}-account-360-{{part}}`, such as `connect-sf-real-time-account-360-inbound`;
+ the guide's views, `{{stack-name}}-view-{{part}}`, such as `connect-sf-real-time-view-main`.


**Template parameters**  

| Parameter | Template | Default | What to enter | 
| --- | --- | --- | --- | 
| `InstanceArn` | Both | None | The ARN of your Connect Customer instance. | 
| `ConnectInstanceUrl` | Both | None | The instance's access URL, the `InstanceAccessUrl` that `aws connect describe-instance` returns. The gateway trusts tokens from it, and the deployment fails if it doesn't match `InstanceArn`. | 
| `SalesforceMyDomainUrl` | Both | None | Your org's My Domain URL, with no trailing slash, such as **https://mycompany.my.salesforce.com**, or **https://mycompany--uat.sandbox.my.salesforce.com** for a sandbox. The host must end in `my.salesforce.com`, `develop.my.salesforce.com`, `sandbox.my.salesforce.com` or `scratch.my.salesforce.com`. | 
| `SalesforceClientId` | Both | None | The External Client App's consumer key. | 
| `SalesforceClientSecretArn` | Both | None | The full ARN of the Secrets Manager secret that holds the consumer secret, including the six characters Secrets Manager adds after the name, under the key `clientSecret` or `consumerSecret`. Encrypt the secret with the default `aws/secretsmanager` key: the stack can't read a secret encrypted with a customer managed key. | 
| `SalesforceIntegrationUsername` | Both | Empty | Optional. The integration user's Salesforce username, the External Client App's **Run As** user. When set, these fail if the **Run As** user has another username:+ a create;<br />+ an update, if the **Run As** user changed since the last deploy;<br />+ scheduled token refreshes, so tool calls fail once the stored token expires.<br />When empty, a change of **Run As** user raises the Run As user changed alarm, and tool calls keep working. Change the **Run As** user and this value in the same change window. Either way, the `SalesforceRunAsUsername` output names the **Run As** user. | 
| `TestQueueArn` | With guides | None | A queue that the agent you test with serves. The stack's inbound flow sends test chats and test calls there, so that agent gets the contact and sees the guide. Your production inbound flows keep their own queues. It must be a queue of the instance in `InstanceArn`; the deploy fails if it isn't. | 
| `CustomOperationsS3Uri` | Both | Empty | Optional. The S3 URI of an OpenAPI file with your own Salesforce operations, which the stack adds as the `salesforce-custom` target. The bucket must be in the stack's account, and the file encrypted with Amazon S3 managed keys. If you deploy with the deployer policy, use its `STAGING_BUCKET`. See [Add your own Salesforce operations](real-time-data-integration-salesforce.md#real-time-data-integration-custom-operations). | 
| `FindRecordModuleArn` | With guides | Empty | Optional. The alias ARN of your own Find the record flow module, published in the instance that `InstanceArn` names, which returns the Salesforce record IDs a contact is about. The guide opens the case it names in the case view, the account in the account view, or several accounts as possible matches. When the module errs, or returns an ID the guide refuses, the guide shows **Customer not found**. Leave it empty for the built-in module, which finds the record by the contact attributes `accountId`, `caseId` and `contactEmail`; see [How the guide finds the record](real-time-data-integration-start.md#real-time-data-integration-find-record) and [Extend the guide with flow modules](real-time-data-integration-modules.md). | 
| `ExistingAssistantArn` | With guides | Empty | The ARN of the Connect assistant the instance already uses. Leave it empty only when the instance has none: the stack then creates an assistant, associates it with the instance, and keeps both when the stack is deleted. Empty on an instance that has an assistant makes the create or update fail and roll back, because an instance can have one assistant association. | 
| `SelfServiceAccountTool` | With guides | `true` | `true` also creates the account agent, which reads only the account in the contact's `accountId`. The stack always creates the knowledge agent, which has no Salesforce tool. `false` creates no account agent. See [Let self-service read the verified account](real-time-data-integration-ai-data.md). | 
| `ConnectAssistantKnowledgeBaseArn` | With guides | Empty | Optional. A Connect assistant knowledge base that isn't associated with the assistant yet, for the stack to associate; the stack removes the association when it is deleted. Empty associates none, and the AI agents search the knowledge bases the assistant already has. | 
| `WrapUp` | With guides | `Disabled` | `Enabled` creates the wrap-up flow and its two views, and sets the flow as the inbound flow's disconnect flow for the agent UI. `Disabled`, the default, creates none of them. An update keeps a stack's own value. Changing a stack to `Disabled` deletes them: first take the wrap-up flow out of the **Set event flow** blocks of your own flows, and publish them. | 
| `NestedTemplateBaseUrl` | With guides | `https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/releases` | Where the stack reads the templates of its two nested stacks: `{{this-URL}}/{{template-version}}/connect-sf-real-time-data-integration-views.template.json` and `{{this-URL}}/{{template-version}}/connect-sf-real-time-data-integration-modules.template.json`. Each version reads its own release's templates. Keep the default unless you copy the release files into your own bucket; then stage both templates under those keys, enter that bucket's URL and folder, with no trailing slash, and give the deployer role `s3:GetObject` on them. | 

Each stack has these outputs, on the **Outputs** tab of the stack in the CloudFormation console. "Both" means both templates.


**Template outputs**  

| Output | Template | What it is | 
| --- | --- | --- | 
| `TemplateVersion` | Both | The template version the stack runs, such as 1.2.0. | 
| `SalesforceRunAsUsername` | Both | The External Client App's **Run As** user, whom every tool call runs as, as of the last create or update that requested a token. `unknown` means the lookup failed; the token refresh function's log names the reason. | 
| `SalesforceRunAsBroadAccess` | Both | `yes` if the **Run As** user has Modify All Data or View All Data, so every tool call can read every record in the org; `no` if it has neither; `unknown` if Salesforce didn't let the user read its permissions, which usually means it lacks View Setup. | 
| `GatewayId` | Both | The gateway's ID. Flows call the gateway's tools by names that include it. | 
| `GatewayUrl` | Both | The gateway's MCP endpoint URL. | 
| `GatewayTargetId` | Both | The ID of the gateway's Salesforce target. | 
| `CustomTargetId` | Both | The ID of the `salesforce-custom` target. Only when `CustomOperationsS3Uri` is set. | 
| `CredentialProviderArn` | Both | The API key credential provider the Salesforce target uses; it reads the token secret. | 
| `TokenSecretArn` | Both | The secret that holds the Salesforce access token the gateway sends. Only the token refresh function writes it. | 
| `TokenRefreshFunctionName` | Both | The function that refreshes the token every five minutes. Invoke it to apply a rotated consumer secret at once. | 
| `McpApplicationArn` | Both | The AWS AppIntegrations application that registers the gateway with Connect Customer. | 
| `IntegrationAssociationId` | Both | The integration association that links the application to your Connect Customer instance. | 
| `VerifyRegistration` | Both | A command to run. It should list one association, for `McpApplicationArn`. | 
| `VerifyAudience` | Both | A command to run after every create or update. It should print the gateway's ID; `pending-gateway-id` means tool calls fail (see [Troubleshoot real-time data integration](real-time-data-integration-troubleshoot.md)). | 
| `ChangeAlertTopicArn` | Both | The Amazon SNS topic that gets every change to the gateway, target, credential provider, token secret and Connect Customer registration, and the stack's four alarms. | 
| `VerifyTrail` | Both | A command to run. It lists the CloudTrail trails that cover this Region; change alerts need one that is logging write management events. | 
| `HealthDashboardUrl` | Both | The stack's health dashboard. | 
| `InboundFlowName`, `InboundFlowArn` | With guides | The inbound flow. Send a test contact to it to try the screen pop. | 
| `GuideFlowArn`, `WrapUpFlowArn` | With guides | The guide flow and the wrap-up flow. | 
| `FindCustomerModuleRef`, `ReadAccountModuleRef`, `CreateCaseModuleRef`, `CreateCustomerModuleRef`, `ReadCaseModuleRef`, `ListCasesModuleRef`, `FindRecordModuleRef`, `ReadVerifiedAccountModuleRef`, `UpdateRecordModuleRef`, `CreateCaseDetailsModuleRef` | With guides | The `v1` alias of each of the stack's ten flow modules, which an **Invoke flow module** block names. `CreateCaseDetailsModuleRef` comes from the nested stack `GuideModules`. | 
| `ConnectAssistantStatus` | With guides | `Created` and the assistant's ARN when the stack created the assistant, or `Reused` and the ARN when `ExistingAssistantArn` named it. | 
| `SampleFlowName`, `SampleFlowArn` | With guides | The AI self-service flow. The stack routes no contact to it. | 
| `AiConsoleSteps` | With guides | The two console steps to do after each create or update, and the step to do before a delete. | 
| `AiSampleCost` | With guides | How the AI self-service flow is billed once contacts are routed to it. | 
| `KnowledgeAgentName`, `KnowledgeAgentArn`, `KnowledgeAgentSecurityProfile` | With guides | The knowledge agent, to set as the assistant's **Self service** default, and the security profile to associate with it and its published version. | 
| `AccountAgentName`, `AccountAgentArn`, `AccountAgentSecurityProfile` | With guides | The account agent and its security profile. Only when the stack creates the account agent. | 
| `AgentAssistAgentName`, `AgentAssistAgentArn`, `AgentAssistAgentSecurityProfile` | With guides | The agent assist AI agent, which the AI self-service flow's **Connect assistant** block names, and its security profile, which you also add to agents who use agent assist. | 
| `ViewMainArn`, `ViewMainBatchedArn`, `ViewCaseCreatedArn`, `ViewCaseFailedArn`, `ViewCaseViewArn`, `ViewCaseErrorArn`, `ViewFindArn`, `ViewFindNewArn`, `ViewCaseRetryArn`, `ViewMatchesArn`, `ViewErrorArn`, `ViewWrapupArn`, `ViewWrapupFailedArn`, `ViewCasesArn`, `ViewEditCustomerArn`, `ViewEditContactArn`, `ViewEditKeptArn` | With guides | The guide's views. `ViewWrapupArn` and `ViewWrapupFailedArn`, with `WrapUpFlowArn`, only when `WrapUp` is `Enabled`. | 

**To download the template**

Download the template you need, its deployer policy, and the `SHA256SUMS` file:


**Template downloads**  

| File | Download URL | 
| --- | --- | 
| Template with the account and case guide | `https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/connect-sf-real-time-data-integration.template.json` | 
| Its deployer policy | `https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/connect-sf-real-time-data-integration.deployer-policy.json` | 
| Gateway-only template | `https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/connect-sf-real-time-data-integration-gateway.template.json` | 
| Its deployer policy | `https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/connect-sf-real-time-data-integration-gateway.deployer-policy.json` | 
| The AI self-service deployer policy, which the template with the account and case guide also needs | `https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/connect-sf-real-time-data-integration-ai-sample.deployer-policy.json` | 
| The views template, which the template with the account and case guide reads as a nested stack | `https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/releases/{{template-version}}/connect-sf-real-time-data-integration-views.template.json` | 
| The modules template, which the template with the account and case guide reads as a nested stack | `https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/releases/{{template-version}}/connect-sf-real-time-data-integration-modules.template.json` | 
| Checksums for the release folder's files | `https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/releases/{{template-version}}/SHA256SUMS` | 
| Checksums for the first five files | `https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/SHA256SUMS` | 

The first five files always hold the latest release. The release folder, `releases/{{template-version}}/`, also holds that version's views and modules templates, which you need only if you host the release files yourself. Check the download:

```
curl -fsSO https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/connect-sf-real-time-data-integration.template.json
curl -fsSO https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com/SHA256SUMS
grep ' connect-sf-real-time-data-integration.template.json$' SHA256SUMS | sha256sum -c
```

It prints `OK`. The check detects a download that doesn't match the published file, such as a corrupted template. On macOS, use `shasum -a 256 -c` in place of `sha256sum -c`. For another file, put its name in the `grep`; for the views and modules templates, use the release folder's `SHA256SUMS`.

The deployer policy is optional: deploy with your own permissions, or with a role that holds the policy. It grants the rights CloudFormation needs to create, update and delete the stack's resources, which give administrator-level control over the following:
+ Every flow, flow module and view in the instance.
+ Every Amazon AppIntegrations application in the account and Region.
+ The IAM roles, functions, gateway and other resources named after the stack.

The policy can create a role named after the stack with any permissions, so holding it is equivalent to administrator access in the account. Your AWS administrator decides who can use the deployer role: give the role, and `iam:PassRole` to pass it to CloudFormation, to people who already have administrator access.

To deploy with the deployer role:

1. Fill in the policy's placeholders: `REGION`, `ACCOUNT_ID`, `STACK_NAME`, `INSTANCE_ID` and `STAGING_BUCKET`. In the policy of the template with the account and case guide, also fill in `DEPLOYER_ROLE`, the role's own name, which CloudFormation passes to the nested stacks `GuideViews` and `GuideModules`. It matches only a role on the default path `/`.

1. Name the role so that it doesn't start with the stack name and a hyphen, because the policy can change roles with that prefix.

1. Choose the stack name: at most 24 characters, or the policy's patterns don't match the resource names, and not another stack's name plus a hyphen and more, or the policy's `STACK_NAME-*` patterns would match that stack's resources too.

1. Attach the policy inline to a role that only CloudFormation can assume.

1. Deploy with the AWS CLI and that role (`--role-arn`).

The template with the account and case guide also needs the AI self-service deployer policy on the same role. It fills in the same placeholders except `STAGING_BUCKET` and `DEPLOYER_ROLE`. Together the two policies are larger than a role's inline policies can be, so create this one as a customer managed policy named `cfn-deployer-{{stack-name}}-ai`, which the upgrade script looks for, and attach it to the role. It gives administrator-level control over every security profile in the instance, the Connect assistant's AI agents and prompts in the account, and the Amazon Lex bots in the account and Region. Holding it is also equivalent to administrator access.

The deployer policy covers both nested stacks, and the AI self-service policy lets the role read the published views and modules templates. If you host the release files in your own bucket (`NestedTemplateBaseUrl`), give the deployer role `s3:GetObject` on both templates there.

**To deploy the stack with the AWS CLI**

Paste the following block at the prompt. It asks for these values:
+ The Region, the template and the stack name.
+ A staging bucket, and the deployer role if you use one.
+ The instance alias and the test queue.
+ The My Domain URL, the consumer key and the secret's name.

It looks up the instance's ARN and access URL, its Connect assistant, the queue's ARN and the secret's ARN for you. When the Region has more than one instance, type the alias from the list; there is no default. The test queue defaults to `rtdi-test-queue`, which the test setup script in Step 1 creates. Before it deploys, it prints the instance, the Region and the stack name and asks `Deploy to {{alias}}? [y/N]`; type **y** to deploy. The templates are larger than CloudFormation accepts inline, so the block downloads the template, checks it against `SHA256SUMS`, checks the views and modules templates that the stack reads with the default `NestedTemplateBaseUrl` against the release folder's `SHA256SUMS`, and stages the template in the bucket, an Amazon S3 bucket that you own in the same Region. To create a bucket, run `aws s3 mb s3://` followed by a new bucket name.

## The deployment script
<a name="real-time-data-integration-code-deployment-script"></a>

```
(
  set -o pipefail
  W=$(mktemp -d); trap 'rm -rf "$W"' EXIT; cd "$W" || exit 1
  BASE=https://ac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com
  R=${AWS_REGION:-us-east-1}
  printf 'Region of your Connect Customer instance [%s]: ' "$R"; read -r REGION; REGION=${REGION:-$R}
  printf 'Template, guide (with the account and case guide) or gateway (gateway only) [guide]: '; read -r KIND
  case "${KIND:-guide}" in guide) FILE=connect-sf-real-time-data-integration.template.json ;;
    gateway) FILE=connect-sf-real-time-data-integration-gateway.template.json ;; *) echo "Enter guide or gateway."; exit 1 ;; esac
  printf 'Stack name [connect-sf-real-time]: '; read -r STACK; STACK=${STACK:-connect-sf-real-time}
  printf 'Staging bucket, an S3 bucket you own in %s: ' "$REGION"; read -r BUCKET
  printf 'Deployer role ARN, or Enter to deploy with your own permissions []: '; read -r ROLE
  ROLE_ARG=(); [ -z "$ROLE" ] || ROLE_ARG=(--role-arn "$ROLE")
  ALIASES=$(aws connect list-instances --region "$REGION" --query 'InstanceSummaryList[].InstanceAlias' --output text) || exit 1
  ALIASES=$(echo "$ALIASES" | tr '\t' '\n' | grep .)
  [ -n "$ALIASES" ] || { echo "No Connect Customer instances in $REGION. Check the Region."; exit 1; }
  echo "Connect Customer instances in $REGION:"; echo "$ALIASES" | sed 's/^/  /'
  if [ "$(echo "$ALIASES" | wc -l)" -eq 1 ]; then
    printf 'Instance alias [%s]: ' "$ALIASES"; read -r ALIAS; ALIAS=${ALIAS:-$ALIASES}
  else
    printf 'Instance alias, typed from the list (there is no default): '; read -r ALIAS
  fi
  [ -n "$ALIAS" ] || { echo "No instance alias entered; nothing was changed."; exit 1; }
  ID=$(aws connect list-instances --region "$REGION" --query "InstanceSummaryList[?InstanceAlias=='$ALIAS'].Id" --output text | grep -m 1 .)
  [ -n "$ID" ] || { echo "No instance named $ALIAS in $REGION."; exit 1; }
  INSTANCE_ARN=$(aws connect describe-instance --region "$REGION" --instance-id "$ID" --query Instance.Arn --output text)
  INSTANCE_URL=$(aws connect describe-instance --region "$REGION" --instance-id "$ID" --query Instance.InstanceAccessUrl --output text)
  PARAMS=("InstanceArn=$INSTANCE_ARN" "ConnectInstanceUrl=${INSTANCE_URL%/}")
  if [ "$FILE" = connect-sf-real-time-data-integration.template.json ]; then
    aws connect list-queues --region "$REGION" --instance-id "$ID" --queue-types STANDARD --query 'QueueSummaryList[].Name' --output text | tr '\t' '\n' | sed 's/^/  /'
    printf 'Test queue name [rtdi-test-queue]: '; read -r QUEUE; QUEUE=${QUEUE:-rtdi-test-queue}
    QUEUE_ARN=$(aws connect list-queues --region "$REGION" --instance-id "$ID" --queue-types STANDARD \
      --query "QueueSummaryList[?Name=='$QUEUE'].Arn" --output text | grep -m 1 .)
    [ -n "$QUEUE_ARN" ] || { echo "No queue named $QUEUE in $ALIAS."; exit 1; }
    PARAMS+=("TestQueueArn=$QUEUE_ARN")
    ASSISTANT=$(aws connect list-integration-associations --region "$REGION" --instance-id "$ID" --integration-type WISDOM_ASSISTANT \
      --query 'IntegrationAssociationSummaryList[0].IntegrationArn' --output text)
    case "$ASSISTANT" in arn:*) echo "Connect assistant: $ASSISTANT" ;; *) ASSISTANT=; echo "Connect assistant: none; the stack creates one." ;; esac
    PARAMS+=("ExistingAssistantArn=$ASSISTANT")
  fi
  printf 'My Domain URL, for example https://mycompany.my.salesforce.com: '; read -r MY_DOMAIN
  printf 'Consumer key: '; read -r KEY
  printf 'Secret name or ARN of the consumer secret [connect-sf-real-time/client]: '; read -r SECRET
  SECRET_ARN=$(aws secretsmanager describe-secret --region "$REGION" --secret-id "${SECRET:-connect-sf-real-time/client}" \
    --query ARN --output text) || exit 1
  PARAMS+=("SalesforceMyDomainUrl=${MY_DOMAIN%/}" "SalesforceClientId=$KEY" "SalesforceClientSecretArn=$SECRET_ARN")
  echo "Instance: $ALIAS   Region: $REGION   Stack: $STACK"
  printf 'Deploy to %s? [y/N]: ' "$ALIAS"; read -r GO
  case "$GO" in y|Y|yes|Yes) ;; *) echo "Nothing was deployed."; exit 0 ;; esac
  curl -fsSO "$BASE/$FILE" && curl -fsSO "$BASE/SHA256SUMS" || { echo "Download failed."; exit 1; }
  # sha256sum where it exists (Linux, CloudShell), else shasum (macOS)
  sum_ok() { if command -v sha256sum >/dev/null 2>&1; then sha256sum -c --status; else shasum -a 256 -c --status; fi; }
  grep " $FILE\$" SHA256SUMS | sum_ok || { echo "The download doesn't match its checksum; nothing was deployed."; exit 1; }
  if [ "$FILE" = connect-sf-real-time-data-integration.template.json ]; then
    # The nested views and modules templates that the stack reads, checked against the release folder's SHA256SUMS
    V=$(grep -o '/[0-9][0-9.]*[0-9]/connect-sf-real-time-data-integration-views.template.json' "$FILE" | head -n 1 | cut -d/ -f2)
    NESTED=$(grep -o 'connect-sf-real-time-data-integration-[a-z]*[.]template[.]json' "$FILE" | sort -u)
    ( mkdir -p rel && cd rel && curl -fsSO "$BASE/releases/$V/SHA256SUMS" \
      && for F in $NESTED; do
        curl -fsSO "$BASE/releases/$V/$F" && grep " $F\$" SHA256SUMS | sum_ok || exit 1; done ) \
      || { echo "The release $V views or modules template doesn't match its checksum; nothing was deployed."; exit 1; }
  fi
  aws cloudformation deploy --region "$REGION" --stack-name "$STACK" --template-file "$FILE" \
    --s3-bucket "$BUCKET" "${ROLE_ARG[@]}" --capabilities CAPABILITY_IAM \
    --parameter-overrides "${PARAMS[@]}"
)
```

It ends with `Successfully created/updated stack`. If it ends with `Failed to create/update the stack`, find the cause as *If the stack fails* in [Step 3: Deploy the CloudFormation stack](real-time-data-integration-resources.md) describes. A stack whose first deployment failed stays in `ROLLBACK_COMPLETE` or `ROLLBACK_FAILED`; delete it before you deploy again with the same stack name. The script finds the Connect assistant that a failed create kept, so you don't need to enter it.

**Check that change alerts reach you**

1. Run the command in the `VerifyTrail` output. If it lists no trail, the stack sends no change alerts; the four alarms still publish to the topic. To check that a trail logs management events, expand the block that follows, copy it, and paste it at the prompt:

## The trail check script
<a name="real-time-data-integration-code-trail-check-script"></a>

```
(
  R=${AWS_REGION:-us-east-1}
  printf 'Region of the stack [%s]: ' "$R"; read -r REGION; REGION=${REGION:-$R}
  TRAILS=$(aws cloudtrail describe-trails --region "$REGION" --query 'trailList[].TrailARN' --output text) || exit 1
  [ -n "$TRAILS" ] || { echo "No trail in $REGION: the stack sends no change alerts."; exit 1; }
  for T in $TRAILS; do
    echo "$T: logging $(aws cloudtrail get-trail-status --region "$REGION" --name "$T" --query IsLogging --output text)," \
      "management events $(aws cloudtrail get-event-selectors --region "$REGION" --trail-name "$T" \
        --query 'EventSelectors[0].IncludeManagementEvents' --output text)"
  done
)
```

Each trail must show `logging True` and `management events True`. `management events None` means the trail uses advanced event selectors; check in the CloudTrail console that they include management events.

**Change alerts**

The stack sends an alert to the `ChangeAlertTopicArn` topic whenever someone does one of these:
+ Changes or deletes the gateway.
+ Creates, changes or deletes a gateway target.
+ Changes or deletes the API key credential provider.
+ Changes the token secret, other than the token refresh function's own writes.
+ Changes the token refresh function's code, configuration or invoke permission, or its schedule.
+ Changes or deletes the Connect Customer application, or deletes the integration association.

A failed attempt alerts too. The same changes to other gateways and applications in the account and Region also alert. Each alert names these, never the request body:
+ the call;
+ the caller;
+ the source IP address;
+ the time;
+ any error code;
+ the resource.

For the template with the account and case guide, the stack also alerts on changes to these:
+ its AI agents and prompts;
+ the assistant's default AI agents;
+ security profiles in your instance;
+ the Read the verified account module;
+ the seven flow modules that agent assist runs.

Change alerts don't cover:
+ Changes to the consumer secret that you store in Secrets Manager.
+ Changes to the stack's IAM roles, including the token refresh function's role.
+ Edits to flows and views in Connect Customer, and, with the gateway-only template, to security profiles.
+ Changes that turn the alerts off, such as disabling the rule, deleting the topic or stopping the trail.

A stack update can also alert; act on an alert you can't match to a change you made.

## Launch Stack by Region
<a name="real-time-data-integration-launch-regions"></a>

Choose **Launch Stack** for the Region of your Connect Customer instance. The tables list Connect Customer Regions and whether the template is available in each.


**Launch the template with the account and case guide, by Region**  

| Connect Customer Region of your instance | Template | 
| --- | --- | 
| US East (N. Virginia) (`us-east-1`) | [![Launch Stack in US East (N. Virginia)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration.template.json&stackName=connect-sf-real-time) | 
| US West (Oregon) (`us-west-2`) | [![Launch Stack in US West (Oregon)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration.template.json&stackName=connect-sf-real-time) | 
| Africa (Cape Town) (`af-south-1`) | Not available: neither the External Tool block nor Amazon Bedrock AgentCore Gateway is available in this Region. | 
| Asia Pacific (Seoul) (`ap-northeast-2`) | [![Launch Stack in Asia Pacific (Seoul)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-2#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration.template.json&stackName=connect-sf-real-time) | 
| Asia Pacific (Singapore) (`ap-southeast-1`) | [![Launch Stack in Asia Pacific (Singapore)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-1#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration.template.json&stackName=connect-sf-real-time) | 
| Asia Pacific (Sydney) (`ap-southeast-2`) | [![Launch Stack in Asia Pacific (Sydney)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-2#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration.template.json&stackName=connect-sf-real-time) | 
| Asia Pacific (Tokyo) (`ap-northeast-1`) | [![Launch Stack in Asia Pacific (Tokyo)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-1#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration.template.json&stackName=connect-sf-real-time) | 
| Canada (Central) (`ca-central-1`) | [![Launch Stack in Canada (Central)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=ca-central-1#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration.template.json&stackName=connect-sf-real-time) | 
| Europe (Frankfurt) (`eu-central-1`) | [![Launch Stack in Europe (Frankfurt)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=eu-central-1#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration.template.json&stackName=connect-sf-real-time) | 
| Europe (London) (`eu-west-2`) | [![Launch Stack in Europe (London)](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=eu-west-2#/stacks/create/review?templateURL=https%3A%2F%2Fac-sf-headless360-cfn-template.s3.us-west-2.amazonaws.com%2Fconnect-sf-real-time-data-integration.template.json&stackName=connect-sf-real-time) | 
| AWS GovCloud (US-West) (`us-gov-west-1`) | Not available: the External Tool block isn't available in this Region. | 