Skip to content

Commit 962ac35

Browse files
committed
Refactor webapp sample to use new modules section
1 parent fbad5e8 commit 962ac35

File tree

5 files changed

+56
-56
lines changed

5 files changed

+56
-56
lines changed

modules/cognito.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,3 @@ Resources:
4949
- openid
5050
SupportedIdentityProviders:
5151
- COGNITO
52-

modules/compliant-bucket.yaml

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,48 @@ Rain:
2828
LogBucketArn: "${Rain::S3Arn}${Rain::LogBucketName}"
2929
ReplicaBucketName: "${AppName}-replicas-${AWS::Region}-${AWS::AccountId}"
3030

31+
Modules:
32+
33+
BucketAccess:
34+
Source: bucket-policy.yaml
35+
Properties:
36+
PolicyBucketName: !Sub ${AppName}-${AWS::Region}-${AWS::AccountId}
37+
38+
ReplicaBucketAccess:
39+
Source: bucket-policy.yaml
40+
Properties:
41+
PolicyBucketName: !Sub ${AppName}-replicas-${AWS::Region}-${AWS::AccountId}
42+
43+
LogBucketAccess:
44+
Source: bucket-policy.yaml
45+
Properties:
46+
PolicyBucketName: !Sub ${Rain::LogBucketName}
47+
Overrides:
48+
Policy:
49+
Properties:
50+
PolicyDocument:
51+
Statement:
52+
- Action: s3:*
53+
Condition:
54+
Bool:
55+
aws:SecureTransport: false
56+
Effect: Deny
57+
Principal:
58+
AWS: '*'
59+
Resource:
60+
- !Sub ${Rain::LogBucketArn}
61+
- !Sub ${Rain::LogBucketArn}/*
62+
- Action: s3:PutObject
63+
Condition:
64+
ArnLike:
65+
aws:SourceArn: !Sub ${Rain::LogBucketArn}/*
66+
StringEquals:
67+
aws:SourceAccount: !Ref AWS::AccountId
68+
Effect: Allow
69+
Principal:
70+
Service: logging.s3.amazonaws.com
71+
Resource:
72+
- !Sub ${Rain::LogBucketArn}/*
3173

3274
Resources:
3375

@@ -67,36 +109,6 @@ Resources:
67109
VersioningConfiguration:
68110
Status: Enabled
69111

70-
LogBucketAccess:
71-
Type: !Rain::Module "bucket-policy.yaml"
72-
Properties:
73-
PolicyBucketName: !Sub ${Rain::LogBucketName}
74-
Overrides:
75-
Policy:
76-
Properties:
77-
PolicyDocument:
78-
Statement:
79-
- Action: s3:*
80-
Condition:
81-
Bool:
82-
aws:SecureTransport: false
83-
Effect: Deny
84-
Principal:
85-
AWS: '*'
86-
Resource:
87-
- !Sub ${Rain::LogBucketArn}
88-
- !Sub ${Rain::LogBucketArn}/*
89-
- Action: s3:PutObject
90-
Condition:
91-
ArnLike:
92-
aws:SourceArn: !Sub ${Rain::LogBucketArn}/*
93-
StringEquals:
94-
aws:SourceAccount: !Ref AWS::AccountId
95-
Effect: Allow
96-
Principal:
97-
Service: logging.s3.amazonaws.com
98-
Resource:
99-
- !Sub ${Rain::LogBucketArn}/*
100112

101113
Bucket:
102114
Type: AWS::S3::Bucket
@@ -131,10 +143,6 @@ Resources:
131143
VersioningConfiguration:
132144
Status: Enabled
133145

134-
BucketAccess:
135-
Type: !Rain::Module "bucket-policy.yaml"
136-
Properties:
137-
PolicyBucketName: !Sub ${AppName}-${AWS::Region}-${AWS::AccountId}
138146

139147
ReplicaBucket:
140148
Type: AWS::S3::Bucket
@@ -167,10 +175,6 @@ Resources:
167175
VersioningConfiguration:
168176
Status: Enabled
169177

170-
ReplicaBucketAccess:
171-
Type: !Rain::Module "bucket-policy.yaml"
172-
Properties:
173-
PolicyBucketName: !Sub ${AppName}-replicas-${AWS::Region}-${AWS::AccountId}
174178

175179
ReplicationPolicy:
176180
Type: AWS::IAM::RolePolicy

modules/rest-api.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ Resources:
3434
- !Ref UserPoolArn
3535
RestApiId: !Ref Api
3636
Type: COGNITO_USER_POOLS
37-

modules/static-site.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ Resources:
8989
ExcludedRules:
9090
- Name: NoUserAgent_HEADER
9191

92+
Modules:
9293
Content:
93-
Type: !Rain::Module "compliant-bucket.yaml"
94+
Source: compliant-bucket.yaml
9495
Properties:
9596
AppName: !Sub ${AppName}-content
9697
EmptyOnDelete: true
@@ -120,7 +121,7 @@ Resources:
120121
Version: "2012-10-17"
121122

122123
CloudFrontLogs:
123-
Type: !Rain::Module "compliant-bucket.yaml"
124+
Source: compliant-bucket.yaml
124125
Properties:
125126
AppName: !Sub ${AppName}-cflogs
126127
EmptyOnDelete: true
@@ -130,4 +131,3 @@ Resources:
130131
OwnershipControls:
131132
Rules:
132133
- ObjectOwnership: BucketOwnerPreferred
133-

test/webapp/webapp.yaml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ Parameters:
1616
Description: This name is used as a prefix for resource names
1717
Default: rain-webapp
1818

19-
Resources:
20-
19+
Modules:
2120
Site:
22-
Type: !Rain::Module "../../modules/static-site.yaml"
21+
Source: ../../modules/static-site.yaml
2322
Properties:
2423
AppName: !Ref AppName
2524
Overrides:
@@ -41,7 +40,7 @@ Resources:
4140
- Rain::OutputValue AppClientId
4241

4342
Cognito:
44-
Type: !Rain::Module "../../modules/cognito.yaml"
43+
Source: ../../modules/cognito.yaml
4544
Properties:
4645
AppName: !Ref AppName
4746
CallbackURL: !Sub "https://${SiteDistribution.DomainName}/index.html"
@@ -50,7 +49,7 @@ Resources:
5049
DependsOn: SiteDistribution
5150

5251
Rest:
53-
Type: !Rain::Module "../../modules/rest-api.yaml"
52+
Source: ../../modules/rest-api.yaml
5453
Properties:
5554
AppName: !Ref AppName
5655
UserPoolArn: !GetAtt CognitoUserPool.Arn
@@ -65,15 +64,15 @@ Resources:
6564
- JwtResourceOptions
6665

6766
TestResource:
68-
Type: !Rain::Module "../../modules/api-resource.yaml"
67+
Source: ../../modules/api-resource.yaml
6968
Metadata:
7069
Comment: This module handles all methods on the /test path on the API. The lambda function code is located in api/resources/test.
7170
Properties:
7271
Name: !Sub ${AppName}-test
7372
RestApi: !Ref RestApi
7473
RestApiDeployment: !Ref RestApiDeployment
75-
BuildScript: ../test/webapp/buildapi.sh
76-
CodePath: ../test/webapp/api/dist/test/lambda-handler.zip
74+
BuildScript: buildapi.sh
75+
CodePath: api/dist/test/lambda-handler.zip
7776
ResourcePath: test
7877
StageName: staging
7978
AuthorizerId: !Ref RestApiAuthorizer
@@ -85,21 +84,21 @@ Resources:
8584
TABLE_NAME: !Ref TestDataTable
8685

8786
TestData:
88-
Type: !Rain::Module "../../modules/simple-table.yaml"
87+
Source: ../../modules/simple-table.yaml
8988
Properties:
9089
TableName: !Sub ${AppName}-test
9190
LambdaRole: !Ref TestResourceHandlerRole
9291

9392
JwtResource:
94-
Type: !Rain::Module "../../modules/api-resource.yaml"
93+
Source: ../../modules/api-resource.yaml
9594
Metadata:
9695
Comment: This module handles all methods on the /jwt path on the API. The lambda function code is located in api/resources/jwt
9796
Properties:
9897
Name: !Sub ${AppName}-jwt
9998
RestApi: !Ref RestApi
10099
RestApiDeployment: !Ref RestApiDeployment
101-
BuildScript: ../test/webapp/buildapi.sh
102-
CodePath: ../test/webapp/api/dist/jwt/lambda-handler.zip
100+
BuildScript: buildapi.sh
101+
CodePath: api/dist/jwt/lambda-handler.zip
103102
ResourcePath: jwt
104103
StageName: staging
105104
AuthorizerId: AWS::NoValue
@@ -136,4 +135,3 @@ Outputs:
136135

137136
CognitoDomainPrefix:
138137
Value: !Ref AppName
139-

0 commit comments

Comments
 (0)