AWSTemplateFormatVersion: '2010-09-09' Description: CloudFormation Template for AppFlow (qs-1t7ksiu6q) Metadata: QSLint: Exclusions: [ W9002, W9003, W9004, W9006 ] QuickStartDocumentation: EntrypointName: "Launch Case Appflow" Order: 4 AWS::CloudFormation::Interface: ParameterGroups: - Label: default: Amazon AppFlow configuration Parameters: - ConnectorProfileNameSalesforce - CaseSalesforce ParameterLabels: CaseSalesforce: default: "Name of the Case object flow" ConnectorProfileNameSalesforce: default: Production radio box from the Salesforce environment section (connection Must be created before deploying ) Parameters: CaseSalesforce: Description: Salesforce Case Objects Type: String ConnectorProfileNameSalesforce: Description: "Select the Production radio box from the Salesforce environment section. Enter the connection name and click Continue. The Connection name must match in every single Cloudformation template for AppFlow logs or any other desired name." Type: String Resources: SalesforceFlow: Type: AWS::AppFlow::Flow Metadata: cfn-lint: config: ignore_checks: - E9101 ignore_reasons: E9101: This is by design due to Salesforce terminology. Properties: Description: AppFlow Flow integrating Salesforce with a Redshift DestinationFlowConfigList: - ConnectorType: !ImportValue ConnectorType ConnectorProfileName: !ImportValue CPRN DestinationConnectorProperties: Redshift: BucketPrefix: !ImportValue S3BucketPrefix ErrorHandlingConfig: FailOnFirstError: true BucketPrefix: Case-Error BucketName: !ImportValue RedshiftLoggingS3Bucket IntermediateBucketName: !ImportValue RedshiftLoggingS3Bucket Object: ods.case FlowName: !Ref CaseSalesforce SourceFlowConfig: ConnectorProfileName: !Ref ConnectorProfileNameSalesforce ConnectorType: Salesforce SourceConnectorProperties: Salesforce: EnableDynamicFieldUpdate: false IncludeDeletedRecords: false Object: Case Tasks: - TaskType: Filter SourceFields: - Id - IsDeleted - MasterRecordId - CaseNumber - ContactId - AccountId - ParentId - SuppliedName - SuppliedEmail - SuppliedPhone - SuppliedCompany - Type - Status - Reason - Subject - Priority - Description - IsClosed - ClosedDate - IsEscalated - OwnerId - CreatedDate - CreatedById - LastModifiedDate - LastModifiedById - SystemModstamp - ContactPhone - ContactMobile - ContactEmail - ContactFax - Comments - LastViewedDate - LastReferencedDate - Origin ConnectorOperator: Salesforce: PROJECTION - TaskType: Map SourceFields: - Id ConnectorOperator: Salesforce: NO_OP DestinationField: caseid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: id - TaskType: Map SourceFields: - IsDeleted ConnectorOperator: Salesforce: NO_OP DestinationField: deleted TaskProperties: - Key: DESTINATION_DATA_TYPE Value: boolean - Key: SOURCE_DATA_TYPE Value: boolean - TaskType: Map SourceFields: - MasterRecordId ConnectorOperator: Salesforce: NO_OP DestinationField: masterrecordid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - CaseNumber ConnectorOperator: Salesforce: NO_OP DestinationField: casenumber TaskProperties: - Key: DESTINATION_DATA_TYPE Value: casenumber - Key: SOURCE_DATA_TYPE Value: string - TaskType: Map SourceFields: - ContactId ConnectorOperator: Salesforce: NO_OP DestinationField: contactid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - AccountId ConnectorOperator: Salesforce: NO_OP DestinationField: accountid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - ParentId ConnectorOperator: Salesforce: NO_OP DestinationField: parentcaseid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - SuppliedName ConnectorOperator: Salesforce: NO_OP DestinationField: name TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: string - TaskType: Map SourceFields: - SuppliedEmail ConnectorOperator: Salesforce: NO_OP DestinationField: emailaddress TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: email - TaskType: Map SourceFields: - SuppliedPhone ConnectorOperator: Salesforce: NO_OP DestinationField: phone TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: string - TaskType: Map SourceFields: - SuppliedCompany ConnectorOperator: Salesforce: NO_OP DestinationField: company TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: string - TaskType: Map SourceFields: - Type ConnectorOperator: Salesforce: NO_OP DestinationField: casetype TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: picklist - TaskType: Map SourceFields: - Status ConnectorOperator: Salesforce: NO_OP DestinationField: status TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: picklist - TaskType: Map SourceFields: - Reason ConnectorOperator: Salesforce: NO_OP DestinationField: casereason TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: picklist - TaskType: Map SourceFields: - Subject ConnectorOperator: Salesforce: NO_OP DestinationField: subject TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: string - TaskType: Map SourceFields: - Priority ConnectorOperator: Salesforce: NO_OP DestinationField: priority TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: picklist - TaskType: Map SourceFields: - Description ConnectorOperator: Salesforce: NO_OP DestinationField: description TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: textarea - TaskType: Map SourceFields: - IsClosed ConnectorOperator: Salesforce: NO_OP DestinationField: closed TaskProperties: - Key: DESTINATION_DATA_TYPE Value: boolean - Key: SOURCE_DATA_TYPE Value: boolean - TaskType: Map SourceFields: - ClosedDate ConnectorOperator: Salesforce: NO_OP DestinationField: closeddate TaskProperties: - Key: DESTINATION_DATA_TYPE Value: timestamp without time zone - Key: SOURCE_DATA_TYPE Value: datetime - TaskType: Map SourceFields: - IsEscalated ConnectorOperator: Salesforce: NO_OP DestinationField: escalated TaskProperties: - Key: DESTINATION_DATA_TYPE Value: boolean - Key: SOURCE_DATA_TYPE Value: boolean - TaskType: Map SourceFields: - OwnerId ConnectorOperator: Salesforce: NO_OP DestinationField: ownerid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - CreatedDate ConnectorOperator: Salesforce: NO_OP DestinationField: createddate TaskProperties: - Key: DESTINATION_DATA_TYPE Value: time without time zone - Key: SOURCE_DATA_TYPE Value: datetime - TaskType: Map SourceFields: - CreatedById ConnectorOperator: Salesforce: NO_OP DestinationField: createdbyid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - LastModifiedDate ConnectorOperator: Salesforce: NO_OP DestinationField: lastmodifieddate TaskProperties: - Key: DESTINATION_DATA_TYPE Value: timestamp without time zone - Key: SOURCE_DATA_TYPE Value: datetime - TaskType: Map SourceFields: - LastModifiedById ConnectorOperator: Salesforce: NO_OP DestinationField: lastmodifiedbyid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - SystemModstamp ConnectorOperator: Salesforce: NO_OP DestinationField: systemmodstamp TaskProperties: - Key: DESTINATION_DATA_TYPE Value: timestamp without time zone - Key: SOURCE_DATA_TYPE Value: datetime - TaskType: Map SourceFields: - ContactPhone ConnectorOperator: Salesforce: NO_OP DestinationField: contactphone TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: phone - TaskType: Map SourceFields: - ContactMobile ConnectorOperator: Salesforce: NO_OP DestinationField: contactmobile TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: phone - TaskType: Map SourceFields: - ContactEmail ConnectorOperator: Salesforce: NO_OP DestinationField: contactemail TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: email - TaskType: Map SourceFields: - ContactFax ConnectorOperator: Salesforce: NO_OP DestinationField: contactfax TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: phone - TaskType: Map SourceFields: - Comments ConnectorOperator: Salesforce: NO_OP DestinationField: internalcomments TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: textarea - TaskType: Map SourceFields: - LastViewedDate ConnectorOperator: Salesforce: NO_OP DestinationField: lastvieweddate TaskProperties: - Key: DESTINATION_DATA_TYPE Value: timestamp without time zone - Key: SOURCE_DATA_TYPE Value: datetime - TaskType: Map SourceFields: - LastReferencedDate ConnectorOperator: Salesforce: NO_OP DestinationField: lastreferenceddate TaskProperties: - Key: DESTINATION_DATA_TYPE Value: timestamp without time zone - Key: SOURCE_DATA_TYPE Value: datetime - TaskType: Map SourceFields: - Origin ConnectorOperator: Salesforce: NO_OP DestinationField: caseorigin TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: picklist TriggerConfig: TriggerType: Scheduled TriggerProperties: DataPullMode: Incremental ScheduleExpression: rate(59minutes) LambdaExecutionRole: DependsOn: SalesforceFlow Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: - appflow.amazonaws.com - lambda.amazonaws.com - redshift.amazonaws.com Action: - sts:AssumeRole Path: "/" ManagedPolicyArns: - !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole - !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole - !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AmazonS3ObjectLambdaExecutionRolePolicy - !Sub arn:${AWS::Partition}:iam::aws:policy/SecretsManagerReadWrite - !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonAppFlowFullAccess - !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonS3FullAccess ActivateAppFlowOnStart: Type: AWS::Lambda::Function DependsOn: LambdaExecutionRole Properties: Handler: index.handler Role: !GetAtt LambdaExecutionRole.Arn Runtime: python3.7 Timeout: 180 Code: ZipFile: !Sub | import json import time import boto3 import cfnresponse def describe_connector(event, context): response = client.describe_connectors( connectorTypes=[]) return {'response': response['connectorConfigurations']} def handler(event, context): try: client = boto3.client('appflow') response = client.start_flow ( flowName="${CaseSalesforce}" ) responseData = {} responseValue = 120 responseData['Data'] = responseValue cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData) responseBody = {'statusCode': 200 , 'Status': 'SUCCESS' } responseBody = json.dumps(responseBody) return responseBody except Exception as e: print(e) Primerinvoke: Type: AWS::CloudFormation::CustomResource DependsOn: ActivateAppFlowOnStart Version: "1.0" Properties: ServiceToken: !GetAtt ActivateAppFlowOnStart.Arn