# AppFlow and Step Functions Proof-of-Concept
## Overview of the Project
![[Pasted image 20221209091402.png]]
1. AppFlow Flow runs, reading from Salesforce, and writes data, if any, to an S3 bucket. Flow is scheduled to run on a cycle (for example “every 5 minutes”).
2. `assets-from-salesforce-launch` Step Functions runs to read from S3 and insert records into a DynamoDB table.
1. It tracks whether an S3 object has been processed to avoid reprocessing.
2. Moves S3 objects to archive after processing.
3. DynamoDB stream invokes [`process-salesforce-assets-stream`](https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/functions/process-salesforce-assets-stream) which examines the DDB data and decides whether to invoke [`salesforce-14-day-temp-pause`](https://us-east-1.console.aws.amazon.com/states/home?region=us-east-1#/statemachines/view/arn:aws:states:us-east-1:113677326486:stateMachine:salesforce-14-day-temp-pause) Step Functions
4. [`salesforce-14-day-temp-pause`](https://us-east-1.console.aws.amazon.com/states/home?region=us-east-1#/statemachines/view/arn:aws:states:us-east-1:113677326486:stateMachine:salesforce-14-day-temp-pause) Step Functions launches.
1. Reads from Account Service
2. Gets provider configs
3. Pauses each provider at Account Service
4. Writes an S3 object for AppFlow to use to update back to Salesforce.
5. `assets-to-salesforce-flow-launch` Step Functions runs. If it finds S3 objects in “pending” then it:
1. Moves them to the AppFlow processing directory.
2. Launches AppFlow
6. EventBridge rule sees that the AppFlow finished. It then launches `assets-to-salesforce-flow-cleanup`.
### Loading from S3 with assets-from-salesforce-launch
An EventBridge rule is configured to run the Step Functions state machine `assets-from-salesforce-launch`.
```json
{
"source": ["aws.appflow"],
"detail-type": ["AppFlow End Flow Run Report"],
"detail": {
"flow-name": ["assets-from-salesforce"],
"status": ["Execution Successful"],
"num-of-records-processed": [{
"anything-but": ["0"]
}]
}
}
```
#### assets-from-salesforce-launch diagram
This is the entirety of the state machine. It does all of its work using native Step Functions Actions and JSON transformations, without any Lambdas or external code.
![[Pasted image 20221209091620.png]]
#### salesforce-14-day-temp-pause diagram
This is the entirety of the state machine. It does all of its work using native Step Functions Actions and JSON transformations, without any Lambdas or external code.
![[Pasted image 20221209091705.png]]
### Updating Data for Salesforce
#### assets-to-salesforce-flow-launch diagram
This is the entirety of the state machine. It does all of its work using native Step Functions Actions and JSON transformations, without any Lambdas or external code.
![[Pasted image 20221209091756.png]]
#### assets-to-salesforce-flow-cleanup diagram
This flow is launched from EventBridge based on a rule:
```json
{
"source": ["aws.appflow"],
"detail-type": ["AppFlow End Flow Run Report"],
"detail": {
"flow-name": ["assets-to-salesforce"],
"status": ["Execution Successful"]
}
}
```
This is the entirety of the state machine. It does all of its work using native Step Functions Actions and JSON transformations, without any Lambdas or external code.
![[Pasted image 20221209091851.png]]
---
Created: 2022-12-09 08:39