-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserverless.yml
94 lines (90 loc) · 3 KB
/
serverless.yml
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
##################################################################################
# CodeRecipe - a marketplace for developers to grab ready to use cloud solutions #
# More details at: <Recipe URL> #
##################################################################################
service: CodeRecipeSample-LambdaAurora
provider:
name: aws
runtime: python2.7
region: us-east-1
stage: ${opt:stage}
dbUser: ${opt:dbUser}
apiKeys:
- ${opt:stage}-lambdaAurora
usagePlan:
quota:
limit: 5000
offset: 0
period: DAY
throttle:
burstLimit: 1
rateLimit: 1
functions:
AuroraCRUD:
handler: handler.handle_aurora_crud
name: ${self:provider.stage}-AuroraCRUD
timeout: 10
environment:
Stage: ${self:provider.stage}
AwsSecretStoreArn: "#{RDSSecret}"
DatabaseName: "auroraDb"
DbClusterArn: "arn:aws:rds:${self:provider.region}:#{AWS::AccountId}:cluster:#{AuroraCrudDBCluster}"
events:
- http:
path: /db-interface
method: POST
cors: true
integration: lambda
private: true
iamRoleStatementsName: ${self:provider.stage}-AuroraCRUD-role
iamRoleStatements:
- Effect: "Allow"
Action:
- "rds-data:ExecuteStatement"
Resource: "arn:aws:rds:${self:provider.region}:#{AWS::AccountId}:cluster:#{AuroraCrudDBCluster}"
- Effect: "Allow"
Action:
- "secretsmanager:GetSecretValue"
Resource: "#{RDSSecret}"
resources:
Resources:
AuroraCrudDBCluster:
Type: AWS::RDS::DBCluster
Properties:
DBClusterIdentifier: ${self:provider.stage}-auraracruddbcluster
MasterUsername: !Join ['', ['{{resolve:secretsmanager:', !Ref RDSSecret, ':SecretString:username}}' ]]
MasterUserPassword: !Join ['', ['{{resolve:secretsmanager:', !Ref RDSSecret, ':SecretString:password}}' ]]
DatabaseName: auroraDb
Engine: aurora
EngineMode: serverless
ScalingConfiguration:
AutoPause: false
MaxCapacity: 8
MinCapacity: 2
RDSSecret:
Type: AWS::SecretsManager::Secret
Properties:
Description: 'Secret for Orders RDS'
GenerateSecretString:
SecretStringTemplate: '{"username": "${self:provider.dbUser}"}'
GenerateStringKey: 'password'
PasswordLength: 16
ExcludeCharacters: '"@/\'
SecretRDSInstanceAttachment:
Type: AWS::SecretsManager::SecretTargetAttachment
Properties:
SecretId: !Ref RDSSecret
TargetId: !Ref AuroraCrudDBCluster
TargetType: AWS::RDS::DBCluster
plugins:
- serverless-python-requirements
- serverless-pseudo-parameters
- serverless-iam-roles-per-function
- serverless-plugin-scripts
custom:
scripts:
hooks:
'deploy:finalize': 'aws rds modify-db-cluster --db-cluster-identifier ${self:provider.stage}-auraracruddbcluster --enable-http-endpoint'
pythonRequirements:
noDeploy: []
dockerizePip: false