AWS Learning
Monitoring & Management

AWS Config

Configuration Recording, Compliance Rules, Remediation, Multi-Account Aggregation

Tổng quan

AWS Config là dịch vụ giúp bạn assess, audit, và evaluate cấu hình của AWS resources. AWS Config liên tục monitors và records resource configurations, cho phép bạn:

  • Theo dõi configuration changes theo thời gian
  • Evaluate compliance với internal policies
  • Troubleshoot configuration issues
  • Security analysis

[!TIP] AWS Config KHÔNG ngăn chặn changes - nó chỉ recording và evaluating. Để prevent changes, dùng kết hợp với SCPs, IAM policies.


Tại sao cần AWS Config?

┌─────────────────────────────────────────────────────────────────────────────┐
│                     Problems AWS Config Solves                              │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  ❌ Không có AWS Config:                                                    │
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │  • Ai đã thay đổi Security Group?                                   │    │
│  │  • S3 bucket public từ khi nào?                                     │    │
│  │  • Có bao nhiêu EC2 instances không có encryption?                  │    │
│  │  • Resources nào violate compliance policies?                       │    │
│  │  • Cấu hình trước khi xảy ra incident là gì?                        │    │
│  └─────────────────────────────────────────────────────────────────────┘    │
│                                                                             │
│  ✅ Với AWS Config:                                                         │
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │  • Configuration history của tất cả resources                       │    │
│  │  • Continuous compliance monitoring                                 │    │
│  │  • Resource relationships và dependencies                           │    │
│  │  • Timeline view cho troubleshooting                                │    │
│  │  • Automatic remediation cho violations                             │    │
│  └─────────────────────────────────────────────────────────────────────┘    │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Kiến trúc và Components

┌─────────────────────────────────────────────────────────────────────────────┐
│                      AWS Config Architecture                                │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │                        AWS Resources                                │    │
│  │  EC2 │ S3 │ RDS │ VPC │ IAM │ Lambda │ Security Groups │ ...         │   │
│  └─────────────────────────────┬───────────────────────────────────────┘    │
│                                │                                            │
│                                │ Configuration Changes                      │
│                                ▼                                            │
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │                        AWS Config                                   │    │
│  │  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐                   │   │
│  │  │ Recorder    │  │Configuration│  │ Config      │                   │   │
│  │  │ (records    │  │ Items       │  │ Rules       │                   │   │
│  │  │  changes)   │  │ (CI)        │  │ (evaluate)  │                   │   │
│  │  └─────────────┘  └─────────────┘  └─────────────┘                   │   │
│  └───────────────────────────┬─────────────────────────────────────────┘    │
│               │              │              │                               │
│               ▼              ▼              ▼                               │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐         │
│  │    S3       │  │    SNS      │  │ EventBridge │  │ Systems     │         │
│  │  (history)  │  │ (notify)    │  │  (events)   │  │ Manager     │         │
│  │             │  │             │  │             │  │ (remediate) │         │
│  └─────────────┘  └─────────────┘  └─────────────┘  └─────────────┘         │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Core Components

ComponentMô tả
Configuration RecorderCaptures configuration changes của resources
Configuration Item (CI)Point-in-time view của resource configuration
Configuration HistoryCollection of CIs cho 1 resource theo thời gian
Configuration SnapshotCollection of CIs cho tất cả resources tại 1 thời điểm
Config RulesDesired configuration settings để evaluate
Conformance PacksCollection of Config Rules deploy cùng nhau

Configuration Items (CI)

CI Structure

┌─────────────────────────────────────────────────────────────────────────────┐
│                     Configuration Item Example                              │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  {                                                                          │
│    "configurationItemVersion": "1.3",                                       │
│    "configurationItemCaptureTime": "2024-01-15T10:30:00.000Z",              │
│    "configurationStateId": "1234567890123",                                 │
│    "resourceType": "AWS::EC2::SecurityGroup",                               │
│    "resourceId": "sg-0abc123def456789",                                     │
│    "resourceName": "web-server-sg",                                         │
│    "awsRegion": "ap-southeast-1",                                           │
│    "accountId": "123456789012",                                             │
│    "configuration": {                                                       │
│      "groupId": "sg-0abc123def456789",                                      │
│      "groupName": "web-server-sg",                                          │
│      "ipPermissions": [                                                     │
│        {                                                                    │
│          "fromPort": 443,                                                   │
│          "toPort": 443,                                                     │
│          "ipRanges": [{"cidrIp": "0.0.0.0/0"}]                              │
│        }                                                                    │
│      ]                                                                      │
│    },                                                                       │
│    "relationships": [                                                       │
│      {                                                                      │
│        "resourceType": "AWS::EC2::Instance",                                │
│        "resourceId": "i-0abc123def456789",                                  │
│        "relationshipName": "Is associated with Instance"                    │
│      }                                                                      │
│    ]                                                                        │
│  }                                                                          │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Supported Resource Types

AWS Config hỗ trợ 300+ resource types, bao gồm:

CategoryResource Types
ComputeEC2 Instance, Auto Scaling Group, Lambda Function
StorageS3 Bucket, EBS Volume, EFS
DatabaseRDS Instance, DynamoDB Table, ElastiCache
NetworkVPC, Subnet, Security Group, ACL, Route Table
SecurityIAM User, Role, Policy, KMS Key
ManagementCloudFormation Stack, CloudTrail Trail

Config Rules

Rule Types

┌─────────────────────────────────────────────────────────────────────────────┐
│                        AWS Config Rule Types                                │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │                      Managed Rules                                  │    │
│  │  • 300+ pre-built rules by AWS                                      │    │
│  │  • Ready to use, no coding required                                 │    │
│  │  • Examples: s3-bucket-public-read-prohibited,                      │    │
│  │              ec2-instance-no-public-ip, rds-storage-encrypted       │    │
│  └─────────────────────────────────────────────────────────────────────┘    │
│                                                                             │
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │                      Custom Rules                                   │    │
│  │  • Lambda-based: Run your own Lambda function                       │    │
│  │  • Guard-based: Use AWS CloudFormation Guard DSL                    │    │
│  │  • Full flexibility với custom logic                                │    │
│  └─────────────────────────────────────────────────────────────────────┘    │
│                                                                             │
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │                   Organizational Rules                              │    │
│  │  • Deploy rules across all accounts in AWS Organizations            │    │
│  │  • Centralized management                                           │    │
│  │  • Consistent compliance across organization                        │    │
│  └─────────────────────────────────────────────────────────────────────┘    │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Trigger Types

TriggerMô tảUse Case
Configuration ChangesEvaluate khi resource thay đổiReal-time compliance
PeriodicEvaluate theo schedule (1h, 3h, 6h, 12h, 24h)Regular audits
HybridCả configuration changes và periodicBest coverage
RuleMô tả
s3-bucket-public-read-prohibitedS3 bucket không public read
s3-bucket-ssl-requests-onlyS3 bucket chỉ chấp nhận SSL
ec2-instance-no-public-ipEC2 không có public IP
rds-storage-encryptedRDS storage được encrypted
rds-multi-az-supportRDS có Multi-AZ enabled
encrypted-volumesEBS volumes được encrypted
iam-password-policyIAM password policy đủ strong
iam-user-mfa-enabledIAM users có MFA enabled
root-account-mfa-enabledRoot account có MFA
vpc-flow-logs-enabledVPC có Flow Logs enabled
cloudtrail-enabledCloudTrail enabled
required-tagsResources có required tags

Config Rule Evaluation

┌─────────────────────────────────────────────────────────────────────────────┐
│                     Config Rule Evaluation Flow                             │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  Resource Change                                                            │
│       │                                                                     │
│       ▼                                                                     │
│  ┌─────────────────┐                                                        │
│  │  AWS Config     │                                                        │
│  │  records CI     │                                                        │
│  └────────┬────────┘                                                        │
│           │                                                                 │
│           ▼                                                                 │
│  ┌─────────────────┐                                                        │
│  │  Trigger Rule   │                                                        │
│  │  Evaluation     │                                                        │
│  └────────┬────────┘                                                        │
│           │                                                                 │
│           ▼                                                                 │
│  ┌─────────────────────────────────────────────────────────────────────┐    │
│  │                      Evaluation Result                              │    │
│  │                                                                     │    │
│  │  ┌──────────────┐     ┌──────────────┐     ┌──────────────┐          │   │
│  │  │  COMPLIANT   │     │NON_COMPLIANT │     │NOT_APPLICABLE│          │   │
│  │  │      ✅      │     │      ❌      │     │      ➖      │          │   │
│  │  │              │     │              │     │              │          │   │
│  │  │ Resource     │     │ Resource     │     │ Rule doesn't │          │   │
│  │  │ meets rule   │     │ violates     │     │ apply to     │          │   │
│  │  │ conditions   │     │ rule         │     │ this resource│          │   │
│  │  └──────────────┘     └──────────────┘     └──────────────┘          │   │
│  │                              │                                       │   │
│  │                              ▼                                      │    │
│  │                    ┌──────────────┐                                  │   │
│  │                    │ Remediation  │ (Optional - SSM Automation)      │   │
│  │                    └──────────────┘                                  │   │
│  └─────────────────────────────────────────────────────────────────────┘    │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Custom Rules

Lambda-based Custom Rule

# Lambda function cho custom Config rule
import json
import boto3
 
def lambda_handler(event, context):
    """
    Custom rule: Kiểm tra EC2 instances có tag 'Environment'
    """
    config = boto3.client('config')
    
    # Parse configuration item
    invoking_event = json.loads(event['invokingEvent'])
    configuration_item = invoking_event['configurationItem']
    
    # Extract instance info
    resource_id = configuration_item['resourceId']
    resource_type = configuration_item['resourceType']
    
    # Default compliance
    compliance = 'NON_COMPLIANT'
    annotation = 'Missing required tag: Environment'
    
    # Check tags
    tags = configuration_item.get('configuration', {}).get('tags', [])
    for tag in tags:
        if tag.get('key') == 'Environment':
            compliance = 'COMPLIANT'
            annotation = 'Resource has required Environment tag'
            break
    
    # Put evaluation result
    config.put_evaluations(
        Evaluations=[
            {
                'ComplianceResourceType': resource_type,
                'ComplianceResourceId': resource_id,
                'ComplianceType': compliance,
                'Annotation': annotation,
                'OrderingTimestamp': configuration_item['configurationItemCaptureTime']
            }
        ],
        ResultToken=event['resultToken']
    )
    
    return {
        'compliance': compliance,
        'resourceId': resource_id
    }

Guard-based Custom Rule

# CloudFormation Guard rule
let s3_buckets = Resources.*[ Type == 'AWS::S3::Bucket' ]
 
rule s3_bucket_encryption_check {
    %s3_buckets {
        Properties.BucketEncryption.ServerSideEncryptionConfiguration[*] {
            ServerSideEncryptionByDefault.SSEAlgorithm == 'AES256' or
            ServerSideEncryptionByDefault.SSEAlgorithm == 'aws:kms'
        }
    }
}
 
rule s3_bucket_versioning_check {
    %s3_buckets {
        Properties.VersioningConfiguration.Status == 'Enabled'
    }
}

Conformance Packs

Tổng quan

Conformance Pack là collection of Config Rules và Remediation Actions được deploy như một đơn vị, giúp:

  • Đơn giản hóa compliance management
  • Deploy consistent rules across accounts
  • Audit compliance với frameworks (PCI-DSS, HIPAA, NIST)

Available Sample Templates

TemplateUse Case
Operational Best Practices for AWS Identity and Access ManagementIAM security
Operational Best Practices for Amazon S3S3 security
Operational Best Practices for Amazon DynamoDBDynamoDB
Operational Best Practices for Encryption and KeysEncryption
Operational Best Practices for LoggingLogging
AWS Control Tower Detective GuardrailsControl Tower
PCI-DSSPayment Card Industry
HIPAA SecurityHealthcare
NIST 800-53Government
CIS AWS Foundations BenchmarkCIS

Conformance Pack Template Example

# conformance-pack-s3-security.yaml
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Conformance Pack for S3 Security'
 
Resources:
  S3BucketPublicReadProhibited:
    Type: AWS::Config::ConfigRule
    Properties:
      ConfigRuleName: s3-bucket-public-read-prohibited
      Description: Check S3 buckets do not allow public read
      Source:
        Owner: AWS
        SourceIdentifier: S3_BUCKET_PUBLIC_READ_PROHIBITED
      MaximumExecutionFrequency: TwentyFour_Hours
 
  S3BucketSSLRequestsOnly:
    Type: AWS::Config::ConfigRule
    Properties:
      ConfigRuleName: s3-bucket-ssl-requests-only
      Description: Check S3 buckets require SSL
      Source:
        Owner: AWS
        SourceIdentifier: S3_BUCKET_SSL_REQUESTS_ONLY
 
  S3BucketEncrypted:
    Type: AWS::Config::ConfigRule
    Properties:
      ConfigRuleName: s3-bucket-server-side-encryption-enabled
      Description: Check S3 buckets have encryption enabled
      Source:
        Owner: AWS
        SourceIdentifier: S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED
 
  S3BucketVersioning:
    Type: AWS::Config::ConfigRule
    Properties:
      ConfigRuleName: s3-bucket-versioning-enabled
      Description: Check S3 buckets have versioning enabled
      Source:
        Owner: AWS
        SourceIdentifier: S3_BUCKET_VERSIONING_ENABLED

Remediation

Automatic Remediation

┌─────────────────────────────────────────────────────────────────────────────┐
│                     Automatic Remediation Flow                              │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  ┌─────────────┐     ┌─────────────┐     ┌─────────────────────────────┐    │
│  │  Config     │     │  Detect     │     │   Systems Manager            │   │
│  │  Rule       │────►│  NON_       │────►│   Automation                 │   │
│  │  Evaluates  │     │  COMPLIANT  │     │                              │   │
│  └─────────────┘     └─────────────┘     │   ┌───────────────────────┐  │   │
│                                           │   │ Remediation Document  │ │   │
│                                           │   │ (SSM Automation)      │ │   │
│                                           │   │                       │ │   │
│                                           │   │ Example:              │ │   │
│                                           │   │ AWS-EnableS3          │ │   │
│                                           │   │ BucketEncryption      │ │   │
│                                           │   └───────────────────────┘ │   │
│                                           └─────────────┬───────────────┘   │
│                                                         │                   │
│                                                         ▼                   │
│                                           ┌─────────────────────────────┐   │
│                                           │   Resource Fixed!           │   │
│                                           │   Re-evaluate → COMPLIANT   │   │
│                                           └─────────────────────────────┘   │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Remediation Types

TypeMô tảUse Case
ManualOperator triggers remediationSensitive resources, cần review
AutomaticRemediation runs automaticallyNon-critical resources
Automatic with retryRetry nếu remediation failsReliable remediation

Common SSM Automation Documents

DocumentAction
AWS-EnableS3BucketEncryptionEnable S3 bucket encryption
AWS-DisableS3BucketPublicReadWriteDisable public access
AWS-EnableEbsEncryptionByDefaultEnable EBS encryption
AWS-EnableCloudTrailLogFileValidationEnable CloudTrail validation
AWS-ConfigureS3BucketLoggingEnable S3 access logging

Multi-Account Multi-Region Aggregation

Aggregator

┌─────────────────────────────────────────────────────────────────────────────┐
│                        Config Aggregator                                    │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                     Management Account                                │  │
│  │                        (Aggregator)                                   │  │
│  │  ┌─────────────────────────────────────────────────────────────────┐   │ │
│  │  │              Aggregated Dashboard                               │   │ │
│  │  │  • Compliance summary across all accounts                       │   │ │
│  │  │  • Resource inventory                                           │   │ │
│  │  │  • Non-compliant resources                                      │   │ │
│  │  └─────────────────────────────────────────────────────────────────┘   │ │
│  └───────────────────────────────────────────────────────────────────────┘  │
│                        ▲           ▲           ▲                            │
│                        │           │           │                            │
│         ┌──────────────┴───┐  ┌────┴────┐  ┌───┴──────────────┐             │
│         │                  │  │         │  │                  │             │
│         ┌──────┴───────────┐  ┌──────┴──┐  ┌┴─────────────────┐             │
│         │  Account A       │  │  Account B  │  │  Account C   │             │
│         │  Region 1+2      │  │  Region 1   │  │  Region 1+3  │             │
│         │                  │  │         │  │                  │             │
│         │ Config data      │  │ Config data │  │ Config data  │             │
│         └──────────────────┘  └─────────┘  └──────────────────┘             │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Aggregator Setup

# Create aggregator for AWS Organization
aws configservice put-configuration-aggregator \
    --configuration-aggregator-name MyOrganizationAggregator \
    --organization-aggregation-source OrganizationEnabled=true,AllAwsRegions=true
 
# Create aggregator for specific accounts
aws configservice put-configuration-aggregator \
    --configuration-aggregator-name MyAccountAggregator \
    --account-aggregation-sources '[
        {
            "AccountIds": ["111111111111", "222222222222"],
            "AwsRegions": ["us-east-1", "ap-southeast-1"],
            "AllAwsRegions": false
        }
    ]'

Advanced Queries

SQL-like Queries

AWS Config hỗ trợ SQL-like queries để query configuration data:

-- Find all EC2 instances with specific instance type
SELECT
    resourceId,
    resourceName,
    configuration.instanceType,
    configuration.state.name
WHERE
    resourceType = 'AWS::EC2::Instance'
    AND configuration.instanceType = 't3.micro'
 
-- Find S3 buckets without encryption
SELECT
    resourceId,
    resourceName,
    configuration.bucketName
WHERE
    resourceType = 'AWS::S3::Bucket'
    AND configuration.serverSideEncryptionConfiguration IS NULL
 
-- Find Security Groups with 0.0.0.0/0 on port 22
SELECT
    resourceId,
    configuration.groupName,
    configuration.ipPermissions
WHERE
    resourceType = 'AWS::EC2::SecurityGroup'
    AND configuration.ipPermissions.ipRanges.cidrIp = '0.0.0.0/0'
    AND configuration.ipPermissions.fromPort = 22
 
-- Count resources by type
SELECT
    resourceType,
    COUNT(*)
GROUP BY
    resourceType
ORDER BY
    COUNT(*) DESC

Query via CLI

# Run advanced query
aws configservice select-resource-config \
    --expression "SELECT resourceId, configuration.instanceType 
                  WHERE resourceType = 'AWS::EC2::Instance'"
 
# Run aggregated query
aws configservice select-aggregate-resource-config \
    --configuration-aggregator-name MyAggregator \
    --expression "SELECT resourceId, accountId, awsRegion 
                  WHERE resourceType = 'AWS::S3::Bucket'"

Notifications và Events

SNS Notifications

┌─────────────────────────────────────────────────────────────────────────────┐
│                     AWS Config Notifications                                │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  AWS Config                                                                 │
│       │                                                                     │
│       │ Configuration Stream                                                │
│       ▼                                                                     │
│  ┌─────────────┐                                                            │
│  │    SNS      │─────────► Email, SMS, HTTP endpoint                        │
│  │   Topic     │                                                            │
│  └─────────────┘                                                            │
│                                                                             │
│  Notification Types:                                                        │
│  • Configuration Item Changes                                               │
│  • Configuration Snapshot Delivery Status                                   │
│  • Configuration History Delivery Status                                    │
│  • Compliance State Changes                                                 │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

EventBridge Integration

// EventBridge Rule cho Config compliance changes
{
    "source": ["aws.config"],
    "detail-type": ["Config Rules Compliance Change"],
    "detail": {
        "configRuleName": ["s3-bucket-public-read-prohibited"],
        "newEvaluationResult": {
            "complianceType": ["NON_COMPLIANT"]
        }
    }
}

AWS Config vs CloudTrail (Chi tiết)

Câu hỏi thường gặp: "CloudTrail làm được hết mà?"

[!IMPORTANT] KHÔNG! CloudTrail và AWS Config có overlap nhưng KHÁC NHAU về mục đích và coverage.

FeatureAWS ConfigCloudTrail
FocusResource configuration STATEAPI activities
RecordsWhat resources look likeWho did what, when
Question answeredS3 bucket hiện config thế nào?Ai đã tạo S3 bucket này?
HistoryConfiguration historyAPI call history
Compliance✅ Config Rules❌ No rules
Remediation✅ SSM Automation❌ No remediation
Use caseCompliance, auditing configurationSecurity investigation, troubleshooting

Chúng OVERLAP nhưng KHÔNG phải Superset

┌──────────────────────────────────────────────────────────────────────────────┐
│             CloudTrail vs AWS Config - Không phải Superset                   │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   ❌ KHÔNG PHẢI: CloudTrail ⊃ AWS Config (CloudTrail chứa hết)               │
│                                                                              │
│   ✅ ĐÚNG: Chúng OVERLAP một phần, nhưng mỗi cái có vùng riêng               │
│                                                                              │
│   ┌─────────────────────────────────────────────────────────────────────┐    │
│   │                                                                     │    │
│   │    CHỈ CloudTrail        OVERLAP           CHỈ AWS Config           │    │
│   │   ┌──────────────┐   ┌──────────────┐   ┌──────────────┐             │   │
│   │   │              │   │              │   │              │             │   │
│   │   │ • Failed API │   │  Resource    │   │ • Periodic   │             │   │
│   │   │   calls      │   │  change      │   │   checks     │             │   │
│   │   │ • Read ops   │   │  events      │   │ • Drift      │             │   │
│   │   │   (Describe) │   │              │   │   detection  │             │   │
│   │   │ • Login      │   │              │   │ • Compliance │             │   │
│   │   │   events     │   │              │   │   rules      │             │   │
│   │   │ • Calls ko   │   │              │   │ • Auto       │             │   │
│   │   │   thay đổi   │   │              │   │   remediate  │             │   │
│   │   │   state      │   │              │   │              │             │   │
│   │   │              │   │              │   │              │             │   │
│   │   └──────────────┘   └──────────────┘   └──────────────┘             │   │
│   │                                                                     │    │
│   └─────────────────────────────────────────────────────────────────────┘    │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

3 Scenarios cụ thể

┌──────────────────────────────────────────────────────────────────────────────┐
│                       3 Scenarios cụ thể                                     │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   SCENARIO 1: S3 bucket TẠO TỪ TRƯỚC đang public                             │
│   ─────────────────────────────────────────────────                          │
│   Không có API call mới nào                                                  │
│   CloudTrail: ❌ Không ghi gì (không có API call)                            │
│   AWS Config: ✅ PHÁT HIỆN "bucket này NON-COMPLIANT" (periodic check)       │
│                                                                              │
│   → AWS Config check ĐỊNH KỲ, không cần đợi API call!                        │
│                                                                              │
│   ─────────────────────────────────────────────────────────────────────────  │
│                                                                              │
│   SCENARIO 2: User cố DELETE bucket nhưng THẤT BẠI (Access Denied)           │
│   ─────────────────────────────────────────────────────────────────          │
│   CloudTrail: ✅ GHI LẠI "DeleteBucket FAILED - AccessDenied"                │
│   AWS Config: ❌ KHÔNG ghi gì (state không đổi)                              │
│                                                                              │
│   → CloudTrail ghi cả failed calls!                                          │
│                                                                              │
│   ─────────────────────────────────────────────────────────────────────────  │
│                                                                              │
│   SCENARIO 3: User chỉ XEM list EC2 (DescribeInstances)                      │
│   ──────────────────────────────────────────────────                         │
│   CloudTrail: ✅ GHI LẠI "DescribeInstances by user X"                       │
│   AWS Config: ❌ KHÔNG ghi gì (state không đổi)                              │
│                                                                              │
│   → CloudTrail ghi read operations!                                          │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

Khi nào dùng gì?

Use CaseAWS ConfigCloudTrail
"SG nào đang mở port 22 ra 0.0.0.0/0?"
"S3 bucket nào đang public?"
"Tự động fix nếu resources violate rules"
"Check tất cả resources có comply không?"
"Ai đã xóa S3 bucket này?"
"Từ IP nào có người login lạ?"
"User nào thay đổi Security Group?"

Complementary Usage: Dùng CẢ HAI

┌─────────────────────────────────────────────────────────────────────────────┐
│                CloudTrail + Config = Complete Picture                       │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  Security Incident Investigation:                                           │
│                                                                             │
│  AWS Config: "Security Group sg-123 hiện đang NON-COMPLIANT                 │
│               vì port 22 open to 0.0.0.0/0"                                 │
│                                                                             │
│  → Đi check CloudTrail                                                      │
│                                                                             │
│  CloudTrail: "User john@company.com gọi AuthorizeSecurityGroupIngress       │
│               lúc 10:30 AM từ IP 1.2.3.4"                                   │
│                                                                             │
│  → Complete Picture: BIẾT cấu hình hiện tại + BIẾT ai đã làm                │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

[!TIP] Ví von để nhớ:

  • CloudTrail = Camera an ninh ghi "AI vào cửa lúc nào"
  • AWS Config = Bảo vệ check "cửa có khóa đúng cách không?"

Cả 2 đều trigger khi có người mở cửa, nhưng ghi lại thông tin khác nhau!


Pricing

┌─────────────────────────────────────────────────────────────────────────────┐
│                        AWS Config Pricing                                   │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  Configuration Items:                                                       │
│  • $0.003 per configuration item recorded                                   │
│                                                                             │
│  Config Rules:                                                              │
│  • $0.001 per rule evaluation                                               │
│  • First 100,000 evaluations: included in price                             │
│                                                                             │
│  Conformance Packs:                                                         │
│  • $0.0012 per conformance pack evaluation per Region                       │
│                                                                             │
│  ─────────────────────────────────────────────────────────────────────────  │
│                                                                             │
│  Example - Medium organization:                                             │
│  • 1,000 resources, changes 5 times/month each = 5,000 CIs                  │
│  • 20 rules, evaluate 5,000 times = 100,000 evaluations                     │
│                                                                             │
│  Cost = (5,000 × $0.003) + (100,000 × $0.001) = $15 + $100 = ~$115/month    │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

CLI Examples

# Start recording
aws configservice start-configuration-recorder \
    --configuration-recorder-name default
 
# Stop recording
aws configservice stop-configuration-recorder \
    --configuration-recorder-name default
 
# Put a Config rule
aws configservice put-config-rule \
    --config-rule '{
        "ConfigRuleName": "s3-bucket-encryption",
        "Description": "Check S3 bucket encryption",
        "Source": {
            "Owner": "AWS",
            "SourceIdentifier": "S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED"
        },
        "Scope": {
            "ComplianceResourceTypes": ["AWS::S3::Bucket"]
        }
    }'
 
# Get compliance details
aws configservice get-compliance-details-by-config-rule \
    --config-rule-name s3-bucket-encryption \
    --compliance-types NON_COMPLIANT
 
# Get resource configuration history
aws configservice get-resource-config-history \
    --resource-type AWS::EC2::SecurityGroup \
    --resource-id sg-0abc123def456789 \
    --limit 5
 
# Deliver configuration snapshot
aws configservice deliver-config-snapshot \
    --delivery-channel-name default

Best Practices

Setup

PracticeMô tả
Enable in all RegionsConfig changes có thể xảy ra ở bất kỳ Region
Use AggregatorCentralized view cho multi-account
Deploy via OrganizationsConsistent setup across accounts
Enable all resource typesĐừng miss important resources

Config Rules

PracticeMô tả
Start with managed rulesQuick wins, đã tested
Use Conformance PacksOrganized, versioned, deployable
Enable remediationAuto-fix non-compliant resources
Set appropriate frequencyBalance between real-time và cost

Monitoring

PracticeMô tả
Set up SNS notificationsAlert on non-compliance
Use EventBridgeTrigger workflows on changes
Regular compliance reportsAudit và review
Integrate with Security HubCentralized security view

Integration với AWS Services

┌─────────────────────────────────────────────────────────────────────────────┐
│                    AWS Config Integrations                                  │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│  Security:                                                                  │
│  • Security Hub ──────► Aggregate findings, compliance scores               │
│  • GuardDuty ──────────► Threat detection                                   │
│  • IAM Access Analyzer ► Access analysis                                    │
│                                                                             │
│  Management:                                                                │
│  • CloudTrail ─────────► API correlation                                    │
│  • Systems Manager ────► Remediation automation                             │
│  • Organizations ──────► Multi-account deployment                           │
│  • Control Tower ──────► Guardrails                                         │
│                                                                             │
│  Monitoring:                                                                │
│  • CloudWatch ─────────► Metrics, alarms                                    │
│  • EventBridge ────────► Event-driven automation                            │
│  • SNS ────────────────► Notifications                                      │
│                                                                             │
│  Storage:                                                                   │
│  • S3 ─────────────────► Configuration history, snapshots                   │
│  • Athena ─────────────► Query historical data                              │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Tổng kết

FeatureMô tả
Configuration RecordingLiên tục record resource configurations
Configuration HistoryTimeline của configuration changes
Config RulesEvaluate compliance với desired state
Conformance PacksDeploy nhiều rules cùng lúc
RemediationAuto-fix non-compliant resources
AggregationMulti-account, multi-region view
Advanced QueriesSQL-like queries trên configuration data

[!IMPORTANT] AWS Config là essential service cho:

  • Compliance auditing - Chứng minh compliance với regulations
  • Security analysis - Detect misconfigurations
  • Change management - Track và understand changes
  • Troubleshooting - "What changed before the incident?"

[!TIP] Combine AWS Config với CloudTrail để có complete picture: WHO (CloudTrail) changed WHAT (Config) and WHEN (both).