Skip to content

Commit f25b24c

Browse files
committed
feat: updated namespace definition. Namespace only gets set once. No longer creating one for each stage as this does not change. Created new templates for shared infra, splitting namespaces from images bucket. Updated templates with references to SSM parameters.
1 parent e8e9f65 commit f25b24c

File tree

15 files changed

+188
-125
lines changed

15 files changed

+188
-125
lines changed

Unicorn.Contracts/Integration/event-schemas.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Resources:
2020
Properties:
2121
Description: 'Event schemas for Unicorn Contracts'
2222
RegistryName:
23-
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}-${Stage}"
23+
Fn::Sub: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}-${Stage}"
2424

2525
EventRegistryPolicy:
2626
Type: AWS::EventSchemas::RegistryPolicy

Unicorn.Contracts/Integration/subscriber-policies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ Resources:
4747
"events:creatorAccount": "${aws:PrincipalAccount}"
4848
StringEquals:
4949
"events:source":
50-
- Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
50+
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
5151
"Null":
5252
"events:source": "false"

Unicorn.Contracts/template.yaml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ Globals:
5454
Environment:
5555
Variables:
5656
DYNAMODB_TABLE: !Ref ContractsTable
57-
SERVICE_NAMESPACE: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
57+
SERVICE_NAMESPACE: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
5858
POWERTOOLS_LOGGER_CASE: PascalCase
59-
POWERTOOLS_SERVICE_NAME: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
59+
POWERTOOLS_SERVICE_NAME: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
6060
POWERTOOLS_TRACE_DISABLED: "false" # Explicitly disables tracing, default
6161
POWERTOOLS_LOGGER_LOG_EVENT: !If [IsProd, "false", "true"] # Logs incoming event, default
6262
POWERTOOLS_LOGGER_SAMPLE_RATE: !If [IsProd, "0.1", "0"] # Debug log sampling percentage, default
63-
POWERTOOLS_METRICS_NAMESPACE: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
63+
POWERTOOLS_METRICS_NAMESPACE: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
6464
POWERTOOLS_LOG_LEVEL: INFO # Log level for Logger (INFO, DEBUG, etc.), default
6565
LOG_LEVEL: INFO # Log level for Logger
6666
Tags:
6767
stage: !Ref Stage
6868
project: !FindInMap [Constants, ProjectName, Value]
69-
namespace: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
69+
namespace: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
7070

7171
Resources:
7272
#### SSM PARAMETERS
@@ -149,7 +149,7 @@ Resources:
149149
Tags:
150150
stage: !Ref Stage
151151
project: !FindInMap [Constants, ProjectName, Value]
152-
namespace: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
152+
namespace: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
153153

154154
UnicornContractsApiLogGroup:
155155
Type: AWS::Logs::LogGroup
@@ -217,7 +217,7 @@ Resources:
217217
- Key: project
218218
Value: !FindInMap [Constants, ProjectName, Value]
219219
- Key: namespace
220-
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
220+
Value: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
221221

222222
#### DEAD LETTER QUEUES
223223
# DeadLetterQueue for UnicornContractsIngestQueue. Contains messages that failed to be processed
@@ -235,7 +235,7 @@ Resources:
235235
- Key: project
236236
Value: !FindInMap [Constants, ProjectName, Value]
237237
- Key: namespace
238-
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
238+
Value: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
239239

240240
#### DYNAMODB TABLE
241241
# Persist Contracts information in DynamoDB
@@ -259,7 +259,7 @@ Resources:
259259
- Key: project
260260
Value: !FindInMap [Constants, ProjectName, Value]
261261
- Key: namespace
262-
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
262+
Value: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
263263

264264
#### EVENT BUS
265265
# Event bus for Unicorn Contract Service used to publish and consume events
@@ -284,7 +284,7 @@ Resources:
284284
Condition:
285285
StringEquals:
286286
events:source:
287-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
287+
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
288288

289289
# Catchall rule used for development purposes.
290290
UnicornContractsCatchAllRule:
@@ -297,9 +297,9 @@ Resources:
297297
account:
298298
- !Ref AWS::AccountId
299299
source:
300-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
301-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
302-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornWebNamespace}}"
300+
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
301+
- "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
302+
- "{{resolve:ssm:/uni-prop/UnicornWebNamespace}}"
303303
State: ENABLED #You may want to disable this rule in production
304304
Targets:
305305
- Arn: !GetAtt UnicornContractsCatchAllLogGroup.Arn
@@ -314,7 +314,7 @@ Resources:
314314
LogGroupName: !Sub
315315
- "/aws/events/${Stage}/${NS}-catchall"
316316
- Stage: !Ref Stage
317-
NS: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
317+
NS: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
318318
RetentionInDays: !FindInMap
319319
- LogsRetentionPeriodMap
320320
- !Ref Stage
@@ -375,7 +375,7 @@ Resources:
375375
Target: !GetAtt UnicornContractsEventBus.Arn
376376
TargetParameters:
377377
EventBridgeEventBusParameters:
378-
Source: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
378+
Source: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
379379
DetailType: ContractStatusChanged
380380
InputTemplate: !ToJsonString
381381
PropertyId: "<$.dynamodb.NewImage.PropertyId.S>"
@@ -431,7 +431,7 @@ Resources:
431431
- Key: project
432432
Value: !FindInMap [Constants, ProjectName, Value]
433433
- Key: namespace
434-
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
434+
Value: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
435435

436436
#### CLOUDFORMATION NESTED STACKS
437437
# CloudFormation Stack with the Contracts Service Event Registry and Schemas

Unicorn.Properties/Integration/event-schemas.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Resources:
1818
Properties:
1919
Description: 'Event schemas for Unicorn Properties'
2020
RegistryName:
21-
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}-${Stage}"
21+
Fn::Sub: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}-${Stage}"
2222

2323
EventRegistryPolicy:
2424
Type: AWS::EventSchemas::RegistryPolicy

Unicorn.Properties/Integration/subscriber-policies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ Resources:
4646
"events:creatorAccount": "${aws:PrincipalAccount}"
4747
StringEquals:
4848
"events:source":
49-
- Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
49+
- "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
5050
"Null":
5151
"events:source": "false"

Unicorn.Properties/Integration/subscriptions.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Resources:
2323
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsEventBusArn}}"
2424
EventPattern:
2525
source:
26-
- Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
26+
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
2727
detail-type:
2828
- ContractStatusChanged
2929
State: ENABLED
@@ -32,7 +32,7 @@ Resources:
3232
Arn:
3333
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesEventBusArn}}"
3434
RoleArn:
35-
Fn::GetAtt: UnicornPropertiesSubscriptionRole.Arn
35+
Fn::GetAtt: [ UnicornPropertiesSubscriptionRole, Arn ]
3636

3737
#### UNICORN WEB EVENT SUBSCRIPTIONS
3838
PublicationApprovalRequestedSubscriptionRule:
@@ -44,7 +44,7 @@ Resources:
4444
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornWebEventBusArn}}"
4545
EventPattern:
4646
source:
47-
- Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornWebNamespace}}"
47+
- "{{resolve:ssm:/uni-prop/UnicornWebNamespace}}"
4848
detail-type:
4949
- PublicationApprovalRequested
5050
State: ENABLED
@@ -53,7 +53,7 @@ Resources:
5353
Arn:
5454
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesEventBusArn}}"
5555
RoleArn:
56-
Fn::GetAtt: UnicornPropertiesSubscriptionRole.Arn
56+
Fn::GetAtt: [ UnicornPropertiesSubscriptionRole, Arn ]
5757

5858

5959
# This IAM role allows EventBridge to assume the permissions necessary to send events
@@ -81,9 +81,10 @@ Outputs:
8181
ContractStatusChangedSubscription:
8282
Description: Rule ARN for Contract service event subscription
8383
Value:
84-
Fn::GetAtt: ContractStatusChangedSubscriptionRule.Arn
84+
Fn::GetAtt: [ ContractStatusChangedSubscriptionRule, Arn ]
8585

8686
PublicationApprovalRequestedSubscription:
8787
Description: Rule ARN for Web service event subscription
8888
Value:
89-
Fn::GetAtt: PublicationApprovalRequestedSubscriptionRule.Arn
89+
Fn::GetAtt: [PublicationApprovalRequestedSubscriptionRule, Arn ]
90+

Unicorn.Properties/template.yaml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ Globals:
5454
Variables:
5555
CONTRACT_STATUS_TABLE: !Ref ContractStatusTable
5656
EVENT_BUS: !Ref UnicornPropertiesEventBus
57-
SERVICE_NAMESPACE: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
57+
SERVICE_NAMESPACE: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
5858
POWERTOOLS_LOGGER_CASE: PascalCase
59-
POWERTOOLS_SERVICE_NAME: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
59+
POWERTOOLS_SERVICE_NAME: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
6060
POWERTOOLS_TRACE_DISABLED: "false" # Explicitly disables tracing, default
6161
POWERTOOLS_LOGGER_LOG_EVENT: !If [IsProd, "false", "true"] # Logs incoming event, default
6262
POWERTOOLS_LOGGER_SAMPLE_RATE: !If [IsProd, "0.1", "0"] # Debug log sampling percentage, default
63-
POWERTOOLS_METRICS_NAMESPACE: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
63+
POWERTOOLS_METRICS_NAMESPACE: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
6464
POWERTOOLS_LOG_LEVEL: INFO # Log level for Logger (INFO, DEBUG, etc.), default
6565
LOG_LEVEL: INFO # Log level for Logger
6666
Tags:
6767
stage: !Ref Stage
6868
project: !FindInMap [Constants, ProjectName, Value]
69-
namespace: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
69+
namespace: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
7070

7171
Resources:
7272
#### SSM PARAMETERS
@@ -105,7 +105,7 @@ Resources:
105105
EventBusName: !GetAtt UnicornPropertiesEventBus.Name
106106
Pattern:
107107
source:
108-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
108+
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
109109
detail-type:
110110
- ContractStatusChanged
111111
RetryPolicy:
@@ -278,7 +278,7 @@ Resources:
278278
EventBusName: !GetAtt UnicornPropertiesEventBus.Name
279279
Pattern:
280280
source:
281-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornWebNamespace}}"
281+
- "{{resolve:ssm:/uni-prop/UnicornWebNamespace}}"
282282
detail-type:
283283
- PublicationApprovalRequested
284284
RetryPolicy:
@@ -293,7 +293,7 @@ Resources:
293293
ContentIntegrityValidator: !GetAtt ContentIntegrityValidatorFunction.Arn
294294
ImageUploadBucketName: !Sub "{{resolve:ssm:/uni-prop/${Stage}/ImagesBucket}}"
295295
EventBusName: !GetAtt UnicornPropertiesEventBus.Name
296-
ServiceName: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
296+
ServiceName: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
297297

298298
# Store ApprovalStateMachineLogGroup workflow execution logs
299299
ApprovalStateMachineLogGroup:
@@ -317,7 +317,7 @@ Resources:
317317
- Key: project
318318
Value: !FindInMap [Constants, ProjectName, Value]
319319
- Key: namespace
320-
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
320+
Value: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
321321
- Key: stage
322322
Value: !Ref Stage
323323

@@ -333,7 +333,7 @@ Resources:
333333
- Key: project
334334
Value: !FindInMap [Constants, ProjectName, Value]
335335
- Key: namespace
336-
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
336+
Value: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
337337
- Key: stage
338338
Value: !Ref Stage
339339

@@ -356,7 +356,7 @@ Resources:
356356
- Key: project
357357
Value: !FindInMap [Constants, ProjectName, Value]
358358
- Key: namespace
359-
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
359+
Value: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
360360
- Key: stage
361361
Value: !Ref Stage
362362

@@ -383,7 +383,7 @@ Resources:
383383
Condition:
384384
StringEquals:
385385
events:source:
386-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
386+
- "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
387387

388388
# Catchall rule used for development purposes. Logs all events matching any of the services to CloudWatch Logs
389389
UnicornPropertiesCatchAllRule:
@@ -396,9 +396,9 @@ Resources:
396396
account:
397397
- !Ref AWS::AccountId
398398
source:
399-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
400-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
401-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornWebNamespace}}"
399+
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
400+
- "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
401+
- "{{resolve:ssm:/uni-prop/UnicornWebNamespace}}"
402402
State: ENABLED #You may want to disable this rule in production
403403
Targets:
404404
- Arn: !GetAtt UnicornPropertiesCatchAllLogGroup.Arn
@@ -413,7 +413,7 @@ Resources:
413413
LogGroupName: !Sub
414414
- "/aws/events/${Stage}/${NS}-catchall"
415415
- Stage: !Ref Stage
416-
NS: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
416+
NS: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
417417
RetentionInDays: !FindInMap [LogsRetentionPeriodMap, !Ref Stage, Days]
418418

419419
# Permissions to allow EventBridge to send logs to CloudWatch
@@ -469,16 +469,16 @@ Resources:
469469
Stage: !Ref Stage
470470

471471
# CloudFormation Stack with the Cross-service EventBus Rules for Properties Service
472-
SubscriptionsStack:
473-
Type: AWS::Serverless::Application
474-
UpdateReplacePolicy: Delete
475-
DeletionPolicy: Delete
476-
DependsOn:
477-
- UnicornPropertiesEventBusArnParam
478-
Properties:
479-
Location: "Integration/subscriptions.yaml"
480-
Parameters:
481-
Stage: !Ref Stage
472+
# SubscriptionsStack:
473+
# Type: AWS::Serverless::Application
474+
# UpdateReplacePolicy: Delete
475+
# DeletionPolicy: Delete
476+
# DependsOn:
477+
# - UnicornPropertiesEventBusArnParam
478+
# Properties:
479+
# Location: "Integration/subscriptions.yaml"
480+
# Parameters:
481+
# Stage: !Ref Stage
482482

483483
Outputs:
484484
#### DYNAMODB OUTPUTS

Unicorn.Shared/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.ONESHELL:
2+
3+
ENVIRONMENTS = local dev prod
4+
5+
.PHONY: deploy-namespaces deploy-images delete-namespaces delete-images
6+
7+
deploy-namespaces: ## Deploys global Unicorn Properties namespaces for all Stages
8+
aws cloudformation create-stack --stack-name uni-prop-namespaces --template-body file://uni-prop-namespaces.yaml --capabilities CAPABILITY_AUTO_EXPAND
9+
10+
deploy-images: ## Deploys shared images stack for local dev prod stages
11+
@for env in $(ENVIRONMENTS); do \
12+
stage=$$env; \
13+
if ! aws cloudformation describe-stacks --stack-name "uni-prop-$$env-images" >/dev/null 2>&1; then \
14+
echo "Creating shared images stack for $$env environment"; \
15+
aws cloudformation create-stack \
16+
--stack-name "uni-prop-$$env-images" \
17+
--template-body file://uni-prop-images.yaml \
18+
--parameters ParameterKey=Stage,ParameterValue=$$stage \
19+
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND || echo "Stack creation failed!"; \
20+
fi; \
21+
done
22+
23+
delete-namespaces: ## Depletes Unicorn Properties namespaces
24+
aws cloudformation delete-stack --stack-name uni-prop-namespaces
25+
26+
delete-images: ## Deletes all shared images stacks
27+
@for env in $(ENVIRONMENTS); do \
28+
stage=$$env; \
29+
if aws cloudformation describe-stacks --stack-name "uni-prop-$$env-images" >/dev/null 2>&1; then \
30+
echo "Deleting shared images stack for $$env environment"; \
31+
aws cloudformation delete-stack \
32+
--stack-name "uni-prop-$$env-images"; \
33+
fi; \
34+
done

Unicorn.Shared/samconfig.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)