Skip to content

Commit 1b58195

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 1b1f743 commit 1b58195

File tree

15 files changed

+168
-106
lines changed

15 files changed

+168
-106
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,18 +54,18 @@ Globals:
5454
Environment:
5555
Variables:
5656
DYNAMODB_TABLE: !Ref ContractsTable
57-
SERVICE_NAMESPACE: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
58-
POWERTOOLS_SERVICE_NAME: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
57+
SERVICE_NAMESPACE: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
58+
POWERTOOLS_SERVICE_NAME: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
5959
POWERTOOLS_TRACE_DISABLED: "false" # Explicitly disables tracing, default
6060
POWERTOOLS_LOGGER_LOG_EVENT: !If [IsProd, "false", "true"] # Logs incoming event, default
6161
POWERTOOLS_LOGGER_SAMPLE_RATE: !If [IsProd, "0.1", "0"] # Debug log sampling percentage, default
62-
POWERTOOLS_METRICS_NAMESPACE: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
62+
POWERTOOLS_METRICS_NAMESPACE: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
6363
POWERTOOLS_LOG_LEVEL: INFO # Log level for Logger (INFO, DEBUG, etc.), default
6464
LOG_LEVEL: INFO # Log level for Logger
6565
Tags:
6666
stage: !Ref Stage
6767
project: !FindInMap [Constants, ProjectName, Value]
68-
namespace: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
68+
namespace: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
6969

7070
Resources:
7171
#### SSM PARAMETERS
@@ -148,7 +148,7 @@ Resources:
148148
Tags:
149149
stage: !Ref Stage
150150
project: !FindInMap [Constants, ProjectName, Value]
151-
namespace: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
151+
namespace: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
152152

153153
UnicornContractsApiLogGroup:
154154
Type: AWS::Logs::LogGroup
@@ -216,7 +216,7 @@ Resources:
216216
- Key: project
217217
Value: !FindInMap [Constants, ProjectName, Value]
218218
- Key: namespace
219-
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
219+
Value: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
220220

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

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

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

288288
# Catchall rule used for development purposes.
289289
UnicornContractsCatchAllRule:
@@ -296,9 +296,9 @@ Resources:
296296
account:
297297
- !Ref AWS::AccountId
298298
source:
299-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
300-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
301-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornWebNamespace}}"
299+
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
300+
- "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
301+
- "{{resolve:ssm:/uni-prop/UnicornWebNamespace}}"
302302
State: ENABLED #You may want to disable this rule in production
303303
Targets:
304304
- Arn: !GetAtt UnicornContractsCatchAllLogGroup.Arn
@@ -313,7 +313,7 @@ Resources:
313313
LogGroupName: !Sub
314314
- "/aws/events/${Stage}/${NS}-catchall"
315315
- Stage: !Ref Stage
316-
NS: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
316+
NS: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
317317
RetentionInDays: !FindInMap
318318
- LogsRetentionPeriodMap
319319
- !Ref Stage
@@ -374,7 +374,7 @@ Resources:
374374
Target: !GetAtt UnicornContractsEventBus.Arn
375375
TargetParameters:
376376
EventBridgeEventBusParameters:
377-
Source: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
377+
Source: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
378378
DetailType: ContractStatusChanged
379379
InputTemplate: !ToJsonString
380380
property_id: "<$.dynamodb.NewImage.property_id.S>"
@@ -430,7 +430,7 @@ Resources:
430430
- Key: project
431431
Value: !FindInMap [Constants, ProjectName, Value]
432432
- Key: namespace
433-
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
433+
Value: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
434434

435435
#### CLOUDFORMATION NESTED STACKS
436436
# 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,18 +54,18 @@ Globals:
5454
Variables:
5555
CONTRACT_STATUS_TABLE: !Ref ContractStatusTable
5656
EVENT_BUS: !Ref UnicornPropertiesEventBus
57-
SERVICE_NAMESPACE: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
58-
POWERTOOLS_SERVICE_NAME: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
57+
SERVICE_NAMESPACE: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
58+
POWERTOOLS_SERVICE_NAME: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
5959
POWERTOOLS_TRACE_DISABLED: "false" # Explicitly disables tracing, default
6060
POWERTOOLS_LOGGER_LOG_EVENT: !If [IsProd, "false", "true"] # Logs incoming event, default
6161
POWERTOOLS_LOGGER_SAMPLE_RATE: !If [IsProd, "0.1", "0"] # Debug log sampling percentage, default
62-
POWERTOOLS_METRICS_NAMESPACE: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
62+
POWERTOOLS_METRICS_NAMESPACE: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
6363
POWERTOOLS_LOG_LEVEL: INFO # Log level for Logger (INFO, DEBUG, etc.), default
6464
LOG_LEVEL: INFO # Log level for Logger
6565
Tags:
6666
stage: !Ref Stage
6767
project: !FindInMap [Constants, ProjectName, Value]
68-
namespace: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
68+
namespace: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
6969

7070
Resources:
7171
#### SSM PARAMETERS
@@ -104,7 +104,7 @@ Resources:
104104
EventBusName: !GetAtt UnicornPropertiesEventBus.Name
105105
Pattern:
106106
source:
107-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
107+
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
108108
detail-type:
109109
- ContractStatusChanged
110110
RetryPolicy:
@@ -277,7 +277,7 @@ Resources:
277277
EventBusName: !GetAtt UnicornPropertiesEventBus.Name
278278
Pattern:
279279
source:
280-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornWebNamespace}}"
280+
- "{{resolve:ssm:/uni-prop/UnicornWebNamespace}}"
281281
detail-type:
282282
- PublicationApprovalRequested
283283
RetryPolicy:
@@ -292,7 +292,7 @@ Resources:
292292
ContentIntegrityValidator: !GetAtt ContentIntegrityValidatorFunction.Arn
293293
ImageUploadBucketName: !Sub "{{resolve:ssm:/uni-prop/${Stage}/ImagesBucket}}"
294294
EventBusName: !GetAtt UnicornPropertiesEventBus.Name
295-
ServiceName: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
295+
ServiceName: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
296296

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

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

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

@@ -382,7 +382,7 @@ Resources:
382382
Condition:
383383
StringEquals:
384384
events:source:
385-
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
385+
- "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
386386

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

418418
# 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)