Skip to content

Commit 00dc865

Browse files
Merge pull request #2 from aws-samples/no-macro
No macro
2 parents 413111f + e6deec4 commit 00dc865

File tree

5 files changed

+60
-98
lines changed

5 files changed

+60
-98
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
**/out-tsc
1010
**/settings.js
1111
**/packaged.template
12+
macro.zip
13+
packaged.template
14+
packaged.zip
15+
s-headers.zip
1216

1317
# dependencies
1418
**/node_modules

templates/acm-certificate.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Parameters:
77
Region:
88
Type: String
99
Default: 'us-east-1'
10-
CustomResourceStack:
10+
CFNCustomProvider:
1111
Type: String
1212

1313
Resources:
@@ -17,20 +17,20 @@ Resources:
1717
DomainName: !Sub '*.${DomainName}'
1818
Region: !Ref Region
1919
ValidationMethod: DNS
20-
ServiceToken: !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:binxio-cfn-certificate-provider'
20+
ServiceToken: !Ref 'CFNCustomProvider'
2121

2222
IssuedCertificate:
2323
Type: Custom::IssuedCertificate
2424
Properties:
2525
CertificateArn: !Ref Certificate
26-
ServiceToken: !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:binxio-cfn-certificate-provider'
26+
ServiceToken: !Ref 'CFNCustomProvider'
2727

2828
CertificateDNSRecord:
2929
Type: Custom::CertificateDNSRecord
3030
Properties:
3131
CertificateArn: !Ref Certificate
3232
DomainName: !Sub '*.${DomainName}'
33-
ServiceToken: !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:binxio-cfn-certificate-provider'
33+
ServiceToken: !Ref 'CFNCustomProvider'
3434

3535
DomainValidationRecord:
3636
Type: AWS::Route53::RecordSetGroup
@@ -48,7 +48,5 @@ Resources:
4848
Outputs:
4949
DNSRecord:
5050
Value: !Sub '${CertificateDNSRecord.Name} ${CertificateDNSRecord.Type} ${CertificateDNSRecord.Value}'
51-
CustomResourceStack:
52-
Value: !Ref CustomResourceStack
5351
CertificateArn:
5452
Value: !Ref Certificate

templates/cloudfront-site.yaml

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AWSTemplateFormatVersion: '2010-09-09'
22
Description: ACFS3 - CloudFront with Header Security and site content
3-
Transform: ['AWS::Serverless-2016-10-31', 'S3Objects']
3+
Transform: 'AWS::Serverless-2016-10-31'
44

55
Parameters:
66
CertificateArn:
@@ -17,7 +17,6 @@ Parameters:
1717
Type: String
1818

1919
Resources:
20-
2120
S3BucketLogs:
2221
Type: AWS::S3::Bucket
2322
DeletionPolicy: Retain
@@ -27,6 +26,9 @@ Resources:
2726
ServerSideEncryptionConfiguration:
2827
- ServerSideEncryptionByDefault:
2928
SSEAlgorithm: AES256
29+
Tags:
30+
- Key: Solution
31+
Value: ACFS3
3032

3133
S3BucketRoot:
3234
Type: AWS::S3::Bucket
@@ -69,6 +71,9 @@ Resources:
6971
CodeUri: ../s-headers.zip
7072
Runtime: 'nodejs12.x'
7173
Timeout: 25
74+
Tags:
75+
- Key: Solution
76+
Value: ACFS3
7277

7378
Lambdaversion:
7479
Type: AWS::Lambda::Version
@@ -79,21 +84,24 @@ Resources:
7984
LambdaEdgeFunctionRole:
8085
Type: AWS::IAM::Role
8186
Properties:
82-
Path: '/'
83-
ManagedPolicyArns:
84-
- 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
85-
AssumeRolePolicyDocument:
86-
Version: '2012-10-17'
87-
Statement:
88-
-
89-
Sid: 'AllowLambdaServiceToAssumeRole'
90-
Effect: 'Allow'
91-
Action:
92-
- 'sts:AssumeRole'
93-
Principal:
94-
Service:
95-
- 'lambda.amazonaws.com'
96-
- 'edgelambda.amazonaws.com'
87+
Path: '/'
88+
ManagedPolicyArns:
89+
- 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
90+
AssumeRolePolicyDocument:
91+
Version: '2012-10-17'
92+
Statement:
93+
-
94+
Sid: 'AllowLambdaServiceToAssumeRole'
95+
Effect: 'Allow'
96+
Action:
97+
- 'sts:AssumeRole'
98+
Principal:
99+
Service:
100+
- 'lambda.amazonaws.com'
101+
- 'edgelambda.amazonaws.com'
102+
Tags:
103+
- Key: Solution
104+
Value: ACFS3
97105

98106
CloudFrontDistribution:
99107
Type: AWS::CloudFront::Distribution
@@ -137,6 +145,9 @@ Resources:
137145
AcmCertificateArn: !Ref 'CertificateArn'
138146
MinimumProtocolVersion: 'TLSv1.1_2016'
139147
SslSupportMethod: 'sni-only'
148+
Tags:
149+
- Key: Solution
150+
Value: ACFS3
140151

141152
CloudFrontOriginAccessIdentity:
142153
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
@@ -157,46 +168,6 @@ Resources:
157168
# The following HosteZoneId is always used for alias records pointing to CF.
158169
HostedZoneId: 'Z2FDTNDATAQYW2'
159170

160-
CopiedIndex:
161-
Type: AWS::S3::Object
162-
Properties:
163-
Source:
164-
Bucket: !Sub 'solution-builders-${AWS::Region}'
165-
Key: !Sub 'amazon-cloudfront-secure-static-site/${Release}/source/website/index.html'
166-
Target:
167-
Bucket: !Ref S3BucketRoot
168-
Key: index.html
169-
170-
CopiedOther:
171-
Type: AWS::S3::Object
172-
Properties:
173-
Source:
174-
Bucket: !Sub 'solution-builders-${AWS::Region}'
175-
Key: !Sub 'amazon-cloudfront-secure-static-site/${Release}/source/website/other.html'
176-
Target:
177-
Bucket: !Ref S3BucketRoot
178-
Key: other.html
179-
180-
CopiedError:
181-
Type: AWS::S3::Object
182-
Properties:
183-
Source:
184-
Bucket: !Sub 'solution-builders-${AWS::Region}'
185-
Key: !Sub 'amazon-cloudfront-secure-static-site/${Release}/source/website/404.html'
186-
Target:
187-
Bucket: !Ref S3BucketRoot
188-
Key: 404.html
189-
190-
CopiedCssStyles:
191-
Type: AWS::S3::Object
192-
Properties:
193-
Source:
194-
Bucket: !Sub 'solution-builders-${AWS::Region}'
195-
Key: !Sub 'amazon-cloudfront-secure-static-site/${Release}/source/website/css/style.css'
196-
Target:
197-
Bucket: !Ref S3BucketRoot
198-
Key: css/style.css
199-
200171
Outputs:
201172
LambdaEdgeFunctionVersion:
202173
Description: Lambda@Edge Function ARN with Version

templates/custom-resource.yaml

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,12 @@ Description: ACFS3 - Cert Provider with DNS validation
33
Transform: AWS::Serverless-2016-10-31
44

55
Resources:
6-
ResourceFunction:
7-
Type: AWS::Serverless::Function
8-
Properties:
9-
Runtime: python2.7
10-
CodeUri: ../macro.zip
11-
Handler: resource.handler
12-
Policies: AmazonS3FullAccess
13-
14-
MacroFunction:
15-
Type: AWS::Serverless::Function
16-
Properties:
17-
Runtime: python3.6
18-
CodeUri: ../macro.zip
19-
Handler: macro.handler
20-
Policies: AmazonS3FullAccess
21-
Environment:
22-
Variables:
23-
LAMBDA_ARN: !GetAtt ResourceFunction.Arn
24-
25-
Macro:
26-
Type: AWS::CloudFormation::Macro
6+
LambdaPermission:
7+
Type: AWS::Lambda::Permission
278
Properties:
28-
Name: S3Objects
29-
FunctionName: !GetAtt MacroFunction.Arn
9+
Action: lambda:InvokeFunction
10+
FunctionName: !GetAtt CFNCustomProvider.Arn
11+
Principal: !GetAtt LambdaRole.Arn
3012

3113
LambdaPolicy:
3214
Type: AWS::IAM::Policy
@@ -45,17 +27,12 @@ Resources:
4527
- acm:DeleteCertificate
4628
Resource:
4729
- '*'
48-
- Effect: Allow
49-
Action:
50-
- lambda:InvokeFunction
51-
Resource:
52-
- !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:binxio-cfn-certificate-provider'
5330
- Effect: Allow
5431
Action:
5532
- logs:*
5633
Resource: arn:aws:logs:*:*:*
5734
Roles:
58-
- !Ref 'LambdaRole'
35+
- !Ref LambdaRole
5936

6037
LambdaRole:
6138
Type: AWS::IAM::Role
@@ -69,6 +46,9 @@ Resources:
6946
Principal:
7047
Service:
7148
- lambda.amazonaws.com
49+
Tags:
50+
- Key: Solution
51+
Value: ACFS3
7252

7353
CFNCustomProviderLogGroup:
7454
Type: AWS::Logs::LogGroup
@@ -80,18 +60,18 @@ Resources:
8060

8161
CFNCustomProvider:
8262
Type: AWS::Serverless::Function
83-
DependsOn:
84-
- LambdaRole
8563
Properties:
8664
CodeUri: s3://binxio-public-us-east-1/lambdas/cfn-certificate-provider-0.2.4.zip
8765
Description: CFN Certificate Domain Resource Record Provider
8866
MemorySize: 128
8967
Handler: provider.handler
90-
Role: !GetAtt 'LambdaRole.Arn'
9168
Timeout: 300
69+
Role: !GetAtt LambdaRole.Arn
9270
Runtime: python3.6
93-
FunctionName: binxio-cfn-certificate-provider
71+
Tags:
72+
- Key: Solution
73+
Value: ACFS3
9474

9575
Outputs:
9676
CFNCustomProvider:
97-
Value: !GetAtt 'CFNCustomProvider.Arn'
77+
Value: !GetAtt CFNCustomProvider.Arn

templates/main.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,20 @@ Resources:
3030
Type: AWS::CloudFormation::Stack
3131
Properties:
3232
TemplateURL: ./custom-resource.yaml
33+
Tags:
34+
- Key: Solution
35+
Value: ACFS3
3336

3437
AcmCertificateStack:
3538
Type: AWS::CloudFormation::Stack
3639
Properties:
3740
TemplateURL: ./acm-certificate.yaml
3841
Parameters:
3942
DomainName: !Ref DomainName
40-
CustomResourceStack: !GetAtt CustomResourceStack.Outputs.CFNCustomProvider
43+
CFNCustomProvider: !GetAtt CustomResourceStack.Outputs.CFNCustomProvider
44+
Tags:
45+
- Key: Solution
46+
Value: ACFS3
4147

4248
CloudFrontStack:
4349
Type: AWS::CloudFormation::Stack
@@ -48,6 +54,9 @@ Resources:
4854
DomainName: !Ref DomainName
4955
SubDomain: !Ref SubDomain
5056
Release: !FindInMap [Solution, Constants, Version]
57+
Tags:
58+
- Key: Solution
59+
Value: ACFS3
5160

5261
Outputs:
5362
CFNCustomProvider:

0 commit comments

Comments
 (0)