Skip to content

Commit 4559eb1

Browse files
authored
Update function's Cloud Formation template to allow using an existing S3 bucket (#766)
1 parent 89d14c3 commit 4559eb1

File tree

1 file changed

+52
-21
lines changed

1 file changed

+52
-21
lines changed

aws/logs_monitoring/template.yaml

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ Parameters:
229229
Type: String
230230
Default: ""
231231
Description: The name of the forwarder bucket to create. If not provided, AWS will generate a unique name.
232+
DdForwarderExistingBucketName:
233+
Type: String
234+
Default: ""
235+
Description: The name of an existing s3 bucket to use. If not provided, a new bucket will be created.
232236
Conditions:
233237
IsAWSChina:
234238
Fn::Equals:
@@ -335,14 +339,18 @@ Conditions:
335339
Fn::Equals:
336340
- Ref: DdFetchStepFunctionsTags
337341
- true
338-
CreateS3BucketForTags:
339-
Fn::Or:
342+
CreateS3Bucket:
343+
Fn::And:
344+
- Fn::Or:
345+
- Fn::Equals:
346+
- Ref: DdFetchLogGroupTags
347+
- true
348+
- Fn::Equals:
349+
- Ref: DdFetchLambdaTags
350+
- true
340351
- Fn::Equals:
341-
- Ref: DdFetchLogGroupTags
342-
- true
343-
- Fn::Equals:
344-
- Ref: DdFetchLambdaTags
345-
- true
352+
- Ref: DdForwarderExistingBucketName
353+
- ""
346354
SetDdUsePrivateLink:
347355
Fn::Equals:
348356
- Ref: DdUsePrivateLink
@@ -466,7 +474,11 @@ Resources:
466474
Code:
467475
Fn::If:
468476
- UseZipCopier
469-
- S3Bucket: !Ref ForwarderBucket
477+
- S3Bucket:
478+
Fn::If:
479+
- CreateS3Bucket
480+
- Ref: ForwarderBucket
481+
- Ref: DdForwarderExistingBucketName
470482
S3Key:
471483
Fn::Sub:
472484
- "aws-dd-forwarder-${DdForwarderVersion}.zip"
@@ -494,9 +506,9 @@ Resources:
494506
- Ref: DdApiKeySecretArn
495507
DD_S3_BUCKET_NAME:
496508
Fn::If:
497-
- CreateS3BucketForTags
509+
- CreateS3Bucket
498510
- Ref: ForwarderBucket
499-
- Ref: AWS::NoValue
511+
- Ref: DdForwarderExistingBucketName
500512
DD_SITE:
501513
Ref: DdSite
502514
DD_TAGS:
@@ -687,10 +699,13 @@ Resources:
687699
- s3:DeleteObject
688700
- s3:ListBucket
689701
Resource:
690-
- Fn::Join:
691-
- "/"
692-
- - Fn::GetAtt: ForwarderBucket.Arn
693-
- "*"
702+
- Fn::If:
703+
- CreateS3Bucket
704+
- Fn::Join:
705+
- "/"
706+
- - Fn::GetAtt: ForwarderBucket.Arn
707+
- "*"
708+
- Fn::Sub: "arn:aws:s3:::${DdForwarderExistingBucketName}/*"
694709
Effect: Allow
695710
# Get the actual log content from the s3 bucket based on the received s3 event.
696711
# Use PermissionsBoundaryArn to limit (allow/deny) access if needed.
@@ -817,6 +832,7 @@ Resources:
817832
# A s3 bucket used by the Forwarder as a datastore
818833
ForwarderBucket:
819834
Type: AWS::S3::Bucket
835+
Condition: CreateS3Bucket
820836
Properties:
821837
BucketName:
822838
Fn::If:
@@ -834,6 +850,7 @@ Resources:
834850
RestrictPublicBuckets: true
835851
ForwarderBucketPolicy:
836852
Type: "AWS::S3::BucketPolicy"
853+
Condition: CreateS3Bucket
837854
Properties:
838855
Bucket: !Ref ForwarderBucket
839856
PolicyDocument:
@@ -855,7 +872,11 @@ Resources:
855872
Condition: UseZipCopier
856873
Properties:
857874
ServiceToken: !GetAtt "ForwarderZipCopier.Arn"
858-
DestZipsBucket: !Ref "ForwarderBucket"
875+
DestZipsBucket:
876+
Fn::If:
877+
- CreateS3Bucket
878+
- Ref: ForwarderBucket
879+
- Ref: DdForwarderExistingBucketName
859880
SourceZipUrl:
860881
Fn::If:
861882
- SetSourceZipUrl
@@ -981,15 +1002,21 @@ Resources:
9811002
- s3:PutObject
9821003
- s3:DeleteObject
9831004
Resource:
984-
- Fn::Join:
985-
- "/"
986-
- - Fn::GetAtt: "ForwarderBucket.Arn"
987-
- "*"
1005+
- Fn::If:
1006+
- CreateS3Bucket
1007+
- Fn::Join:
1008+
- "/"
1009+
- - Fn::GetAtt: "ForwarderBucket.Arn"
1010+
- "*"
1011+
- Fn::Sub: "arn:aws:s3:::${DdForwarderExistingBucketName}/*"
9881012
- Effect: Allow
9891013
Action:
9901014
- s3:ListBucket
9911015
Resource:
992-
- Fn::GetAtt: "ForwarderBucket.Arn"
1016+
- Fn::If:
1017+
- CreateS3Bucket
1018+
- Fn::GetAtt: "ForwarderBucket.Arn"
1019+
- Fn::Sub: "arn:aws:s3:::${DdForwarderExistingBucketName}"
9931020
- !If
9941021
- SetS3SourceZip
9951022
- Effect: Allow
@@ -1022,7 +1049,10 @@ Outputs:
10221049
ForwarderBucketName:
10231050
Description: Name of the S3 bucket used by the Forwarder
10241051
Value:
1025-
Ref: ForwarderBucket
1052+
Fn::If:
1053+
- CreateS3Bucket
1054+
- Ref: ForwarderBucket
1055+
- Ref: DdForwarderExistingBucketName
10261056
Export:
10271057
Name:
10281058
Fn::Sub: ${AWS::StackName}-ForwarderBucketName
@@ -1089,6 +1119,7 @@ Metadata:
10891119
- DdApiUrl
10901120
- DdTraceIntakeUrl
10911121
- AdditionalTargetLambdaArns
1122+
- DdForwarderExistingBucketName
10921123
- DdForwarderBucketName
10931124
ParameterLabels:
10941125
DdApiKey:

0 commit comments

Comments
 (0)