Skip to content
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

Use Service-linked role for Config, and record global resources based on home region #10

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 2 additions & 3 deletions ct_configrecorder_override_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def assume_role(account_id, role='AWSControlTowerExecution'):

# ControlTower created configuration recorder with name "aws-controltower-BaselineConfigRecorder" and we will update just that
try:
role_arn = 'arn:aws:iam::' + account_id + ':role/aws-controltower-ConfigRecorderRole'
role_arn = 'arn:aws:iam::' + account_id + ':role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig'

CONFIG_RECORDER_EXCLUSION_RESOURCE_STRING = os.getenv('CONFIG_RECORDER_EXCLUDED_RESOURCE_LIST')
CONFIG_RECORDER_EXCLUSION_RESOURCE_LIST = CONFIG_RECORDER_EXCLUSION_RESOURCE_STRING.split(',')
Expand All @@ -98,7 +98,7 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
'roleARN': role_arn,
'recordingGroup': {
'allSupported': True,
'includeGlobalResourceTypes': False
'includeGlobalResourceTypes': True if os.getenv('CONTROL_TOWER_HOME_REGION') == aws_region else False
}
})
logging.info(f'Response for put_configuration_recorder :{response} ')
Expand All @@ -110,7 +110,6 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
'roleARN': role_arn,
'recordingGroup': {
'allSupported': False,
'includeGlobalResourceTypes': False,
'exclusionByResourceTypes': {
'resourceTypes': CONFIG_RECORDER_EXCLUSION_RESOURCE_LIST
},
Expand Down
14 changes: 11 additions & 3 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ Parameters:
Description: List of all resource types to be excluded from Config Recorder
Default: "AWS::HealthLake::FHIRDatastore,AWS::Pinpoint::Segment,AWS::Pinpoint::ApplicationSettings"
Type: String

ControlTowerHomeRegion:
Type: String

CloudFormationVersion:
Type: String
Default: 2

PythonRuntimeVersion:
Type: String
Default: python3.11

Resources:
LambdaZipsBucket:
Expand All @@ -38,7 +45,7 @@ Resources:
S3Key: ct-blogs-content/ct_configrecorder_override_producer.zip
Handler: ct_configrecorder_override_producer.lambda_handler
Role: !GetAtt ProducerLambdaExecutionRole.Arn
Runtime: python3.10
Runtime: !Ref PythonRuntimeVersion
MemorySize: 128
Timeout: 300
Architectures:
Expand Down Expand Up @@ -70,7 +77,7 @@ Resources:
S3Key: ct-blogs-content/ct_configrecorder_override_consumer_v2.zip
Handler: ct_configrecorder_override_consumer.lambda_handler
Role: !GetAtt ConsumerLambdaExecutionRole.Arn
Runtime: python3.10
Runtime: !Ref PythonRuntimeVersion
MemorySize: 128
Timeout: 180
Architectures:
Expand All @@ -80,6 +87,7 @@ Resources:
Variables:
LOG_LEVEL: INFO
CONFIG_RECORDER_EXCLUDED_RESOURCE_LIST: !Ref ConfigRecorderExcludedResourceTypes
CONTROL_TOWER_HOME_REGION: !Ref ControlTowerHomeRegion

ConsumerLambdaEventSourceMapping:
Type: AWS::Lambda::EventSourceMapping
Expand Down Expand Up @@ -245,7 +253,7 @@ Resources:
Properties:
Description: Copies objects from the S3 bucket to a new location.
Handler: index.handler
Runtime: python3.10
Runtime: !Ref PythonRuntimeVersion
Role: !GetAtt 'CopyZipsRole.Arn'
ReservedConcurrentExecutions: 1
Timeout: 300
Expand Down