-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-processing-cfn.yaml
137 lines (130 loc) · 3.85 KB
/
pre-processing-cfn.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
AWSTemplateFormatVersion: '2010-09-09'
Transform: "AWS::Serverless-2016-10-31"
# CloudFormation template in YAML to setup an automated process to update revisions to datasets in AWS Data Exchange
Parameters:
S3Bucket:
Type: String
Default: rearc-data-provider
Description: Provide the S3 Bucket name where this dataset resides. For e.g. rearc-data-provider
DataSetName:
Type: String
Description: Name of the dataset
DataSetArn:
Type: String
Description: ARN for the AWS Data Exchange dataset that needs to be updated
ProductId:
Type: String
Description: ID of the AWS Data Exchange product that needs to be updated
Region:
Type: String
Default: us-east-1
Description: AWS Region for AWS Data Exchange
Resources:
# Create an IAM role for Lambda to use
LambdaRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Version: 2012-10-17
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
- arn:aws:iam::aws:policy/AmazonS3FullAccess
- arn:aws:iam::796406704065:policy/AWSDataExchangeService
- arn:aws:iam::aws:policy/AWSMarketplaceSellerFullAccess
Path: /
# Create a Lambda function that will update daily revisions to AWS Data Exchange dataset
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName:
!Join
- ''
- - 'source-for-'
- !Ref DataSetName
Description: "Source revision updates to AWS Data Exchange data set"
Runtime: "python3.7"
Code:
S3Bucket:
Fn::Sub: ${S3Bucket}
S3Key:
!Join
- ''
- - Fn::Sub: ${DataSetName}
- '/automation/pre-processing-code.zip'
Handler: "lambda_function.lambda_handler"
MemorySize: 256
Timeout: 120
Role:
Fn::GetAtt:
- LambdaRole
- Arn
Environment:
Variables:
RDP_ROLE_ARN: !Sub ${RearcDataPlatformRoleArn}
RDP_EXTERNAL_ID: !Sub ${RearcDataPlatformExternalId}
ASSET_BUCKET: !Sub ${AssetBucket}
MANIFEST_BUCKET: !Sub ${ManifestBucket}
CUSTOMER_ID: !Sub ${CustomerId}
DATASET_NAME: !Sub ${DataSetName}
DATASET_ARN: !Sub ${DataSetArn}
PRODUCT_ID: !Sub ${ProductId}
REGION: !Sub ${Region}
# Layers:
# - Ref: PyRearcADXLayer
Layers: ["arn:aws:lambda:us-east-1:796406704065:layer:rearc-data-utils:42"]
ScheduledRule:
Type: AWS::Events::Rule
Properties:
Description: "ScheduledRule"
ScheduleExpression: "cron(0 18 ? * 6 *)"
State: "ENABLED"
Targets:
-
Arn:
Fn::GetAtt:
- "LambdaFunction"
- "Arn"
Id: "TargetFunctionV1"
PermissionForEventsToInvokeLambda:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Ref: "LambdaFunction"
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn:
Fn::GetAtt:
- "ScheduledRule"
- "Arn"
version:
Type: AWS::Lambda::Version
Properties:
FunctionName: !Ref "LambdaFunction"
asyncconfig:
Type: AWS::Lambda::EventInvokeConfig
Properties:
DestinationConfig:
OnFailure:
Destination: arn:aws:sns:us-east-1:796406704065:adx-lambda-error
FunctionName: !Ref "LambdaFunction"
MaximumEventAgeInSeconds: 300
MaximumRetryAttempts: 2
Qualifier: $LATEST
Outputs:
LambdaRoleARN:
Description: Role for Lambda execution.
Value:
Fn::GetAtt:
- LambdaRole
- Arn
LambdaFunctionName:
Value:
Ref: LambdaFunction