Skip to content

Commit 2793d6f

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

File tree

15 files changed

+167
-105
lines changed

15 files changed

+167
-105
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
# API GW Cloudwatch Log Group
155155
UnicornContractsApiLogGroup:
@@ -218,7 +218,7 @@ Resources:
218218
- Key: project
219219
Value: !FindInMap [Constants, ProjectName, Value]
220220
- Key: namespace
221-
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
221+
Value: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
222222

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

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

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

290290
# Catchall rule used for development purposes.
291291
UnicornContractsCatchAllRule:
@@ -298,9 +298,9 @@ Resources:
298298
account:
299299
- !Ref AWS::AccountId
300300
source:
301-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
302-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
303-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornWebNamespace}}"
301+
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
302+
- "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
303+
- "{{resolve:ssm:/uni-prop/UnicornWebNamespace}}"
304304
State: ENABLED #You may want to disable this rule in production
305305
Targets:
306306
- Arn: !GetAtt UnicornContractsCatchAllLogGroup.Arn
@@ -315,7 +315,7 @@ Resources:
315315
LogGroupName: !Sub
316316
- "/aws/events/${Stage}/${NS}-catchall"
317317
- Stage: !Ref Stage
318-
NS: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
318+
NS: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
319319
RetentionInDays: !FindInMap
320320
- LogsRetentionPeriodMap
321321
- !Ref Stage
@@ -376,7 +376,7 @@ Resources:
376376
Target: !GetAtt UnicornContractsEventBus.Arn
377377
TargetParameters:
378378
EventBridgeEventBusParameters:
379-
Source: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
379+
Source: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
380380
DetailType: ContractStatusChanged
381381
InputTemplate: !ToJsonString
382382
property_id: "<$.dynamodb.NewImage.property_id.S>"
@@ -432,7 +432,7 @@ Resources:
432432
- Key: project
433433
Value: !FindInMap [Constants, ProjectName, Value]
434434
- Key: namespace
435-
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
435+
Value: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
436436

437437
#### CLOUDFORMATION NESTED STACKS
438438
# 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: 6 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,9 @@ 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 ]

unicorn_properties/template.yaml

Lines changed: 15 additions & 15 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

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)