Skip to content

feat: namespace refactoring #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
**/.aws-sam/
.vscode/*
.vscode/settings.json
**/cdk.out/
2 changes: 1 addition & 1 deletion unicorn_contracts/integration/event-schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Resources:
Properties:
Description: 'Event schemas for Unicorn Contracts'
RegistryName:
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}-${Stage}"
Fn::Sub: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}-${Stage}"

EventRegistryPolicy:
Type: AWS::EventSchemas::RegistryPolicy
Expand Down
2 changes: 1 addition & 1 deletion unicorn_contracts/integration/subscriber-policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ Resources:
"events:creatorAccount": "${aws:PrincipalAccount}"
StringEquals:
"events:source":
- Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
"Null":
"events:source": "false"
40 changes: 22 additions & 18 deletions unicorn_contracts/template.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
AWSTemplateFormatVersion: 2010-09-09
AWSTemplateFormatVersion: "2010-09-09"
Transform:
- AWS::LanguageExtensions
- AWS::Serverless-2016-10-31
Expand All @@ -12,10 +12,10 @@ Metadata:
config:
ignore_checks:
- ES4000 # Rule disabled because the CatchAll Rule doesn't need a DLQ
- ES6000 # Rule disabled because SQS DLOs don't need a RedrivePolicy
- ES6000 # Rule disabled because SQS DLQs don't need a RedrivePolicy
- WS2001 # Rule disabled because check does not support !ToJsonString transform
- ES1001 # Rule disabled because our Lambda functions don't need DestinationConfig.OnFailure
- W3002
- W3002 # Rule disabled as nested templates are being packaged

Parameters:
Stage:
Expand Down Expand Up @@ -54,19 +54,19 @@ Globals:
Environment:
Variables:
DYNAMODB_TABLE: !Ref ContractsTable
SERVICE_NAMESPACE: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
SERVICE_NAMESPACE: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
POWERTOOLS_LOGGER_CASE: PascalCase
POWERTOOLS_SERVICE_NAME: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
POWERTOOLS_SERVICE_NAME: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
POWERTOOLS_TRACE_DISABLED: "false" # Explicitly disables tracing, default
POWERTOOLS_LOGGER_LOG_EVENT: !If [IsProd, "false", "true"] # Logs incoming event, default
POWERTOOLS_LOGGER_SAMPLE_RATE: !If [IsProd, "0.1", "0"] # Debug log sampling percentage, default
POWERTOOLS_METRICS_NAMESPACE: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
POWERTOOLS_METRICS_NAMESPACE: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
POWERTOOLS_LOG_LEVEL: INFO # Log level for Logger (INFO, DEBUG, etc.), default
LOG_LEVEL: INFO # Log level for Logger
Tags:
stage: !Ref Stage
project: !FindInMap [Constants, ProjectName, Value]
namespace: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
namespace: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"

Resources:
#### SSM PARAMETERS
Expand Down Expand Up @@ -149,7 +149,7 @@ Resources:
Tags:
stage: !Ref Stage
project: !FindInMap [Constants, ProjectName, Value]
namespace: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
namespace: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"

# API GW Cloudwatch Log Group
UnicornContractsApiLogGroup:
Expand Down Expand Up @@ -218,7 +218,7 @@ Resources:
- Key: project
Value: !FindInMap [Constants, ProjectName, Value]
- Key: namespace
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
Value: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"

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

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

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

# Catchall rule used for development purposes.
UnicornContractsCatchAllRule:
Expand All @@ -298,9 +298,9 @@ Resources:
account:
- !Ref AWS::AccountId
source:
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
- !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornWebNamespace}}"
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
- "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
- "{{resolve:ssm:/uni-prop/UnicornWebNamespace}}"
State: ENABLED #You may want to disable this rule in production
Targets:
- Arn: !GetAtt UnicornContractsCatchAllLogGroup.Arn
Expand All @@ -315,7 +315,7 @@ Resources:
LogGroupName: !Sub
- "/aws/events/${Stage}/${NS}-catchall"
- Stage: !Ref Stage
NS: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
NS: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
RetentionInDays: !FindInMap
- LogsRetentionPeriodMap
- !Ref Stage
Expand Down Expand Up @@ -376,7 +376,7 @@ Resources:
Target: !GetAtt UnicornContractsEventBus.Arn
TargetParameters:
EventBridgeEventBusParameters:
Source: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
Source: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
DetailType: ContractStatusChanged
InputTemplate: !ToJsonString
property_id: "<$.dynamodb.NewImage.property_id.S>"
Expand Down Expand Up @@ -432,12 +432,14 @@ Resources:
- Key: project
Value: !FindInMap [Constants, ProjectName, Value]
- Key: namespace
Value: !Sub "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
Value: "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"

#### CLOUDFORMATION NESTED STACKS
# CloudFormation Stack with the Contracts Service Event Registry and Schemas
EventSchemasStack:
Type: AWS::Serverless::Application
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
Properties:
Location: "integration/event-schemas.yaml"
Parameters:
Expand All @@ -446,6 +448,8 @@ Resources:
# CloudFormation Stack with the Cross-service EventBus policy for Contracts Service
SubscriberPoliciesStack:
Type: AWS::Serverless::Application
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
DependsOn:
- UnicornContractsEventBusNameParam
Properties:
Expand Down
4 changes: 2 additions & 2 deletions unicorn_properties/integration/event-schemas.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
AWSTemplateFormatVersion: '2010-09-09'
AWSTemplateFormatVersion: "2010-09-09"
Description: Event Schemas for use by the Properties Service

Parameters:
Expand All @@ -18,7 +18,7 @@ Resources:
Properties:
Description: 'Event schemas for Unicorn Properties'
RegistryName:
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}-${Stage}"
Fn::Sub: "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}-${Stage}"

EventRegistryPolicy:
Type: AWS::EventSchemas::RegistryPolicy
Expand Down
4 changes: 2 additions & 2 deletions unicorn_properties/integration/subscriber-policies.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
AWSTemplateFormatVersion: '2010-09-09'
AWSTemplateFormatVersion: "2010-09-09"
Description: >
Defines the event bus policies that determine who can create rules on the event bus to
subscribe to events published by Unicorn Properties Service.
Expand Down Expand Up @@ -46,6 +46,6 @@ Resources:
"events:creatorAccount": "${aws:PrincipalAccount}"
StringEquals:
"events:source":
- Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesNamespace}}"
- "{{resolve:ssm:/uni-prop/UnicornPropertiesNamespace}}"
"Null":
"events:source": "false"
14 changes: 7 additions & 7 deletions unicorn_properties/integration/subscriptions.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
AWSTemplateFormatVersion: '2010-09-09'
AWSTemplateFormatVersion: "2010-09-09"
Description: Defines the rule for the events (subscriptions) that Unicorn Properties wants to consume.

Parameters:
Expand All @@ -23,7 +23,7 @@ Resources:
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsEventBusArn}}"
EventPattern:
source:
- Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornContractsNamespace}}"
- "{{resolve:ssm:/uni-prop/UnicornContractsNamespace}}"
detail-type:
- ContractStatusChanged
State: ENABLED
Expand All @@ -32,7 +32,7 @@ Resources:
Arn:
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesEventBusArn}}"
RoleArn:
Fn::GetAtt: UnicornPropertiesSubscriptionRole.Arn
Fn::GetAtt: [ UnicornPropertiesSubscriptionRole, Arn ]

#### UNICORN WEB EVENT SUBSCRIPTIONS
PublicationApprovalRequestedSubscriptionRule:
Expand All @@ -44,7 +44,7 @@ Resources:
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornWebEventBusArn}}"
EventPattern:
source:
- Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornWebNamespace}}"
- "{{resolve:ssm:/uni-prop/UnicornWebNamespace}}"
detail-type:
- PublicationApprovalRequested
State: ENABLED
Expand All @@ -53,7 +53,7 @@ Resources:
Arn:
Fn::Sub: "{{resolve:ssm:/uni-prop/${Stage}/UnicornPropertiesEventBusArn}}"
RoleArn:
Fn::GetAtt: UnicornPropertiesSubscriptionRole.Arn
Fn::GetAtt: [ UnicornPropertiesSubscriptionRole, Arn ]


# This IAM role allows EventBridge to assume the permissions necessary to send events
Expand Down Expand Up @@ -81,9 +81,9 @@ Outputs:
ContractStatusChangedSubscription:
Description: Rule ARN for Contract service event subscription
Value:
Fn::GetAtt: ContractStatusChangedSubscriptionRule.Arn
Fn::GetAtt: [ ContractStatusChangedSubscriptionRule, Arn ]

PublicationApprovalRequestedSubscription:
Description: Rule ARN for Web service event subscription
Value:
Fn::GetAtt: PublicationApprovalRequestedSubscriptionRule.Arn
Fn::GetAtt: [ PublicationApprovalRequestedSubscriptionRule, Arn ]
Loading