AWSTemplateFormatVersion: '2010-09-09' Description: CloudFormation Template for AppFlow (qs-1t7ksiu7e) Metadata: QSLint: Exclusions: [ W9002, W9003, W9004, W9006 ] QuickStartDocumentation: EntrypointName: "Launch Opportunity Appflow" Order: 7 AWS::CloudFormation::Interface: ParameterGroups: - Label: default: Amazon AppFlow configuration Parameters: - ConnectorProfileNameSalesforce - OpportunitySalesforce ParameterLabels: OpportunitySalesforce: default: "Name of the Oportunity object flow" ConnectorProfileNameSalesforce: default: Production radio box from the Salesforce environment section (connection Must be created before deploying ) Parameters: OpportunitySalesforce: Description: Salesforce Opportunity 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 Properties: Description: AppFlow Flow integrating Saleforce with a Redshift DestinationFlowConfigList: - ConnectorType: !ImportValue ConnectorType ConnectorProfileName: !ImportValue CPRN DestinationConnectorProperties: Redshift: BucketPrefix: !ImportValue S3BucketPrefix ErrorHandlingConfig: FailOnFirstError: true BucketPrefix: Opportunity-Error BucketName: !ImportValue RedshiftLoggingS3Bucket IntermediateBucketName: !ImportValue RedshiftLoggingS3Bucket Object: ods.opportunity FlowName: !Ref OpportunitySalesforce SourceFlowConfig: ConnectorProfileName: !Ref ConnectorProfileNameSalesforce ConnectorType: Salesforce SourceConnectorProperties: Salesforce: EnableDynamicFieldUpdate: false IncludeDeletedRecords: false Object: Opportunity Tasks: - TaskType: Filter SourceFields: - HasOverdueTask - HasOpenActivity - HasOpportunityLineItem - IsWon - IsClosed - IsDeleted - FiscalYear - FiscalQuarter - Amount - ContactId - CreatedById - LastAmountChangedHistoryId - Fiscal - LastModifiedById - OwnerId - Pricebook2Id - CampaignId - ForecastCategory - Type - LeadSource - NextStep - StageName - Name - CloseDate - AccountId - Id - LastActivityDate - LastModifiedDate - CreatedDate - LastReferencedDate - LastViewedDate - SystemModstamp - Probability - Description ConnectorOperator: Salesforce: PROJECTION - TaskType: Map SourceFields: - HasOverdueTask ConnectorOperator: Salesforce: NO_OP DestinationField: hasoverduetask TaskProperties: - Key: DESTINATION_DATA_TYPE Value: boolean - Key: SOURCE_DATA_TYPE Value: boolean - TaskType: Map SourceFields: - HasOpenActivity ConnectorOperator: Salesforce: NO_OP DestinationField: hasopenactivity TaskProperties: - Key: DESTINATION_DATA_TYPE Value: boolean - Key: SOURCE_DATA_TYPE Value: boolean - TaskType: Map SourceFields: - HasOpportunityLineItem ConnectorOperator: Salesforce: NO_OP DestinationField: haslineitem TaskProperties: - Key: DESTINATION_DATA_TYPE Value: boolean - Key: SOURCE_DATA_TYPE Value: boolean - TaskType: Map SourceFields: - IsWon ConnectorOperator: Salesforce: NO_OP DestinationField: won TaskProperties: - Key: DESTINATION_DATA_TYPE Value: boolean - Key: SOURCE_DATA_TYPE Value: boolean - 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: - FiscalYear ConnectorOperator: Salesforce: NO_OP DestinationField: fiscalyear TaskProperties: - Key: DESTINATION_DATA_TYPE Value: integer - Key: SOURCE_DATA_TYPE Value: int - TaskType: Map SourceFields: - FiscalQuarter ConnectorOperator: Salesforce: NO_OP DestinationField: fiscalquarter TaskProperties: - Key: DESTINATION_DATA_TYPE Value: integer - Key: SOURCE_DATA_TYPE Value: int - TaskType: Map SourceFields: - Amount ConnectorOperator: Salesforce: NO_OP DestinationField: amount TaskProperties: - Key: DESTINATION_DATA_TYPE Value: integer - Key: SOURCE_DATA_TYPE Value: currency - 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: - CreatedById ConnectorOperator: Salesforce: NO_OP DestinationField: createdbyid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - LastAmountChangedHistoryId ConnectorOperator: Salesforce: NO_OP DestinationField: opportunityhistoryid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - Fiscal ConnectorOperator: Salesforce: NO_OP DestinationField: fiscalperiod TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - 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: - OwnerId ConnectorOperator: Salesforce: NO_OP DestinationField: ownerid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - Pricebook2Id ConnectorOperator: Salesforce: NO_OP DestinationField: pricebookid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - CampaignId ConnectorOperator: Salesforce: NO_OP DestinationField: campaignid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: reference - TaskType: Map SourceFields: - ForecastCategory ConnectorOperator: Salesforce: NO_OP DestinationField: forecastcategory TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: picklist - TaskType: Map SourceFields: - Type ConnectorOperator: Salesforce: NO_OP DestinationField: opportunitytype TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: picklist - TaskType: Map SourceFields: - LeadSource ConnectorOperator: Salesforce: NO_OP DestinationField: leadsource TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: picklist - TaskType: Map SourceFields: - NextStep ConnectorOperator: Salesforce: NO_OP DestinationField: nextstep TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: string - TaskType: Map SourceFields: - StageName ConnectorOperator: Salesforce: NO_OP DestinationField: stage TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: picklist - TaskType: Map SourceFields: - Name ConnectorOperator: Salesforce: NO_OP DestinationField: name TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: string - TaskType: Map SourceFields: - CloseDate ConnectorOperator: Salesforce: NO_OP DestinationField: closedate TaskProperties: - Key: DESTINATION_DATA_TYPE Value: date - Key: SOURCE_DATA_TYPE Value: date - 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: - Id ConnectorOperator: Salesforce: NO_OP DestinationField: opportunityid TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: id - TaskType: Map SourceFields: - LastActivityDate ConnectorOperator: Salesforce: NO_OP DestinationField: lastactivity TaskProperties: - Key: DESTINATION_DATA_TYPE Value: date - Key: SOURCE_DATA_TYPE Value: date - TaskType: Map SourceFields: - LastModifiedDate ConnectorOperator: Salesforce: NO_OP DestinationField: lastmodifieddate TaskProperties: - Key: DESTINATION_DATA_TYPE Value: date - Key: SOURCE_DATA_TYPE Value: datetime - TaskType: Map SourceFields: - CreatedDate ConnectorOperator: Salesforce: NO_OP DestinationField: createddate TaskProperties: - Key: DESTINATION_DATA_TYPE Value: date - 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: - 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: - 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: - Probability ConnectorOperator: Salesforce: NO_OP DestinationField: probabilitypercentage TaskProperties: - Key: DESTINATION_DATA_TYPE Value: numeric - Key: SOURCE_DATA_TYPE Value: percent - TaskType: Map SourceFields: - Description ConnectorOperator: Salesforce: NO_OP DestinationField: description TaskProperties: - Key: DESTINATION_DATA_TYPE Value: character varying - Key: SOURCE_DATA_TYPE Value: textarea # TriggerConfig: # TriggerType: OnDemand 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="${OpportunitySalesforce}" ) 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