Skip to content

youngwjung/eb-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 

Repository files navigation

AWS Elastic Beanstalk

Elastic Beanstalk์€ AWS์— ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ฐฐํฌํ•˜๋Š” ๊ฐ€์žฅ ๊ฐ„ํŽธํ•˜๊ณ  ๋น ๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ Java, .NET, PHP, Node.js, Python, Ruby, Go, Docker๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Apache, Nginx, IIS์™€ ๊ฐ™์€ ์„œ๋ฒ„์—์„œ ๊ตฌ๋™๋˜๋Š” ์›น์„œ๋น„์Šค๋“ค์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๋ฅผ ๋Œ€์‹ ํ•ด์„œ ์ธํ”„๋ผ๋ฅผ ํ”„๋กœ๋น„์ €๋‹ํ•ด์ฃผ๊ณ  ์—…๋ฐ์ดํŠธ ๋ฐ ํŒจ์น˜๋„ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ ์šฉํ• ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ธํ”„๋ผ ์šด์˜ ์˜ค๋ฒ„ํ—ค๋“œ๋“ฑ์„ ์ค„์—ฌ์„œ ๊ฐœ๋ฐœ์— ๋” ์ง‘์ค‘ํ• ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” PaaS ์ž…๋‹ˆ๋‹ค.

Lab Overview

  1. Open Source Python Django Application์„ Elastic Beanstalk์— ๋ฐฐํฌ

  2. ๊ตฌ์„ฑํŒŒ์ผ(ebextensions)๋กœ ํ™˜๊ฒฝ๊ตฌ์„ฑ Customization

  3. AWS CodePipeline ์œผ๋กœ ๋ฐฐํฌ ์ž๋™ํ™” ๊ตฌ์„ฑ

  4. AWS KMS & Systems Manager๋กœ Parameter ์•”ํ˜ธํ™”

์‹œ์ž‘ํ•˜๊ธฐ์ „์—

  1. ๋ณธ Hands-on lab์—์„œ ์‚ฌ์šฉํ•  Application ์˜ˆ์ œ๋Š” MDN (the Mozilla Developer Network) ์—์„œ ๋งŒ๋“  ํŠœํ† ๋ฆฌ์–ผ์˜ ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.
  2. ๋ณธ Hands-on lab์€ AWS Seoul region ๊ธฐ์ค€์œผ๋กœ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. Region์„ Seoul (ap-northeast-2)๋กœ ๋ณ€๊ฒฝ ํ›„ ์ง„ํ–‰ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.
  3. AWS Credit ์ถ”๊ฐ€ํ•˜๊ธฐ
  4. Lab ํ™˜๊ฒฝ ๊ตฌ์ถ•

Elastic Beanstalk ํ™˜๊ฒฝ ๊ตฌ์„ฑ

  1. AWS Management Console์—์„œ ์ขŒ์ธก ์ƒ๋‹จ์— ์žˆ๋Š” [Services] ๋ฅผ ์„ ํƒํ•˜๊ณ  ๊ฒ€์ƒ‰์ฐฝ์—์„œ Elastic Beanstalk์„ ๊ฒ€์ƒ‰ํ•˜๊ฑฐ๋‚˜ [Compute] ๋ฐ‘์— ์žˆ๋Š” [Elastic Beanstalk] ๋ฅผ ์„ ํƒ

  2. [Create New Application] โ†’ Application Name = local-library โ†’ [Create]

  3. Elastic Beanstalk Application Dashboard ์—์„œ [Actions] โ†’ [Create environment] โ†’ Web server environment ๐Ÿ”˜ โ†’ [Select]

  4. Environment name = local-library-<YOUR_INITIAL>,
    Domain = local-library-<YOUR_INITIAL>,
    Platform = ๐Ÿ”˜ Python - Amazon Linux 1,
    Application code = ๐Ÿ”˜ Sample application,
    โ†’ [Configure more options]

  5. Configuration presets = ๐Ÿ”˜ High availability

  6. [Capacity] โ†’ [Modify] โ†’ Instance type = m5.large, Metric = CPUUtilization, Unit = Percent, Upper threshold = 80, Lower threshold = 30 โ†’ [Save]

  7. [Security] โ†’ [Modify] โ†’ EC2 key pair = EC2 ์ธ์Šคํ„ด์Šค์— ์ ‘์†ํ•  Key pair ์ง€์ •, IAM instance profile = eb-lab-InstanceProfile-XXXXX โ†’ [Save]

  8. [Network] โ†’ [Modify] โ†’ VPC = eb-vpc, Load balancer visibility = Public, Load balancer subnets = ๋ชจ๋“  public subnet ์„ ํƒ, Instance subnets = ๋ชจ๋“  private subnet ์„ ํƒ โ†’ [Save]

  9. [Create environment]

Application ๋ฐฐํฌ

  1. AWS Management Console์—์„œ ์ขŒ์ธก ์ƒ๋‹จ์— ์žˆ๋Š” [Services] ๋ฅผ ์„ ํƒํ•˜๊ณ  ๊ฒ€์ƒ‰์ฐฝ์—์„œ Cloud9๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ฑฐ๋‚˜ [Developer Tools] ๋ฐ‘์— ์žˆ๋Š” [Cloud9] ๋ฅผ ์„ ํƒ โ†’ [Open IDE]

  2. ํ•ด๋‹น ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•ด์„œ EB CLI ์„ค์น˜

  3. ํ•ด๋‹น Git Repository๋ฅผ Fork (GitHub ๊ณ„์ • ํ•„์ˆ˜)

  4. Forkingํ•œ Repository๋ฅผ Cloud9์œผ๋กœ ํ™˜๊ฒฝ์œผ๋กœ Clone

    git clone http://<REPOSITORY_URL>
  5. ์œ„์—์„œ Cloneํ•œ ๋กœ์ปฌ Git Repository์˜ Root ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™ ํ›„ EB CLI ์„ค์ •

    eb init
    Select a default region: 10) ap-northeast-2 : Asia Pacific (Seoul)
    Select an application to use: 1) local-library
    Do you wish to continue with CodeCommit? (y/N): N
  6. EB CLI๋กœ Application ๋ฐฐํฌ

    eb deploy
  7. Elastic Beanstalk ๋„๋ฉ”์ธ ์ฃผ์†Œ๋กœ ์ ‘์†ํ•ด์„œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ํ™•์ธ. ์—๋Ÿฌ๋ฐœ์ƒ์‹œ ์•„๋ž˜์˜ ์ปค๋งจ๋“œ๋กœ Log๋ฅผ ํ™•์ธ

    eb logs -a

Configuration & Customization

WSGI ์„ค์ •

  1. EB Dashboard์—์„œ [Configuration] โ†’ Category๊ฐ€ Software ์ธ ํƒญ์—์„œ [Modify] ํด๋ฆญ โ†’ WSGIPath = locallibrary/wsgi.py โ†’ [Apply]

ALLOWED_HOSTS ์„ค์ •

  1. locallibrary/settings.py ํŒŒ์ผ์„ ์—ด๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •

    ALLOWED_HOSTS = ['.elasticbeanstalk.com']
  2. EB CLI๋กœ Application ๋ฐฐํฌ ํ›„ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์ ์šฉ๋ฌ๋Š”์ง€ ํ™•์ธ

  3. ์ˆ˜์ •ํ•œ ์ฝ”๋“œ๋ฅผ Commit & Push

    git add .
    git commit -m "fixed DisallowedHost error"
    git push
  4. EB CLI๋กœ Application ๋ฐฐํฌ ํ›„ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์ ์šฉ๋ฌ๋Š”์ง€ ํ™•์ธ

Custom script ์‹คํ–‰

  1. ebextensions ํด๋” ์ƒ์„ฑ

    mkdir .ebextensions
  2. configuration ํŒŒ์ผ ์…์„ฑ

    touch .ebextensions/05_django.config
  3. .ebextensions/05_django.config ํŒŒ์ผ์„ ์—ด๊ณ  ์•„๋ž˜์˜ ์ฝ”๋“œ๋ธ”๋ก ๋ถ™์—ฌ๋„ฃ๊ธฐ

    container_commands:
      01_collect_static:
        command: python manage.py collectstatic
      02_migrate:
        command: python manage.py migrate --noinput
        leader_only: true

Database ์—ฐ๊ฒฐ

  1. PostgreSQL client ์„ค์น˜

    sudo yum install postgresql -y
  2. RDS ์ธ์Šคํ„ด์Šค์— ์ ‘์† (RDS Endpoint๋Š” RDS Console์—์„œ ํ™•์ธ ๊ฐ€๋Šฅ)

    psql -h eb-postgres.xxxxxx.ap-northeast-2.rds.amazonaws.com -U master postgres
  3. ์ ‘์†์ด ์•ˆ๋  ๊ฒฝ์šฐ RDS ์ธ์Šคํ„ด์Šค์— ๋ถ™์–ด์žˆ๋Š” Security Group์— Cloud9 ์ธ์Šคํ„ด์Šค์—์„œ PostgreSQL ํฌํŠธ๋กœ ์ ‘์† ๊ฐ€๋Šฅํ•œ Inbound rule์„ ์„ค์ •

  4. ์•„๋ž˜์™€ ๊ฐ™์ด ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ์ฐฝ์ด ๋‚˜์˜ฌ๊ฒฝ์šฐ, asdf1234๋ฅผ ์ž…๋ ฅ

    Password for user master:
  5. Database ์ƒ์„ฑ

    CREATE DATABASE local_library;
  6. Database User ์ƒ์„ฑ

    CREATE USER local_library WITH PASSWORD 'asdf1234';
  7. Database User์— ๊ถŒํ•œ ๋ถ€์—ฌ

    GRANT ALL PRIVILEGES ON DATABASE local_library TO local_library;
  8. locallibrary/settings.py ํŒŒ์ผ์„ ์—ด๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'local_library',
            'USER': 'local_library',
            'PASSWORD': 'asdf1234',
            'HOST': '<RDS_ENDPOINT>',
            'PORT': '5432',
        }
    }
  9. locallibrary/settings.py ํŒŒ์ผ์„ ์—ด๊ณ  ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ธ”๋ก์„ ์‚ญ์ œ

    # Heroku: Update database configuration from $DATABASE_URL.
    import dj_database_url
    db_from_env = dj_database_url.config(conn_max_age=500)
    DATABASES['default'].update(db_from_env)
  10. ์ˆ˜์ •ํ•œ ์ฝ”๋“œ๋ฅผ Commit & Pushํ•˜๊ณ  EB CLI๋ฅผ ํ†ตํ•ด์„œ Application ๋ฐฐํฌ

CodePipeline ๊ตฌ์ถ•

  1. AWS Management Console์—์„œ ์ขŒ์ธก ์ƒ๋‹จ์— ์žˆ๋Š” [Services] ๋ฅผ ์„ ํƒํ•˜๊ณ  ๊ฒ€์ƒ‰์ฐฝ์—์„œ CodePipeline๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ฑฐ๋‚˜ [Developer Tools] ๋ฐ‘์— ์žˆ๋Š” [CodePipeline] ๋ฅผ ์„ ํƒ

  2. [Create pipeline] โ†’ Pipeline name = eb, Service role = New service role โ†’ [Next] โ†’ Source provider = GitHub โ†’ [Connect to GitHub] โ†’ Repository = ๋žฉ ์‹œ์ž‘ํ• ๋•Œ Forkingํ•œ Repository, Branch = master โ†’ [Skip build stage]

  3. Deploy provider = AWS Elastic Beanstalk, Application name๊ณผ Environment name์— ์œ„์—์„œ ์ƒ์„ฑํ•œ ๋ฆฌ์†Œ์Šค๋“ค์„ ๋„ฃ๊ณ  [Next] โ†’ [Create pipeline]

Autoscaling ์„ค์ •

ELB Health check ์„ค์ •

  1. locallibrary/settings.py ํŒŒ์ผ์„ ์—ด๊ณ  ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ธ”๋ก์„ ๋ถ™์—ฌ๋„ฃ๊ธฐ

    # Get the private IP address of the instance to stop Sentry errors from
    # Load Balancer health checks.
    import requests
    
    PRIVATE_IP_URL = 'http://169.254.169.254/latest/meta-data/local-ipv4'
    PRIVATE_IP_REQUEST_DATA = requests.get(PRIVATE_IP_URL)
    if PRIVATE_IP_REQUEST_DATA:
        IP_ADDRESS = PRIVATE_IP_REQUEST_DATA.text
    
        ALLOWED_HOSTS.append(IP_ADDRESS)
  2. requirements.txtํŒŒ์ผ์„ ์—ด๊ณ  ์•„๋ž˜์˜ ๋ผ์ธ์„ ์ถ”๊ฐ€

    requests==2.22.0
  3. ์ˆ˜์ •ํ•œ ์ฝ”๋“œ๋ฅผ Commit & Push

  4. Load balancer ์„ค์ •์—์„œ Health check path๋ฅผ /catalog/๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ์ ์šฉ

  5. Health Status๊ฐ€ โœ… OK ๋กœ ๋ณ€ํ–ˆ๋Š”์ง€ ํ™•์ธ

Autoscaling ํ…Œ์ŠคํŠธ

  1. AWS Management Console ์ขŒ์ธก ์ƒ๋‹จ์— ์žˆ๋Š” [Services] ๋ฅผ ์„ ํƒํ•˜๊ณ  ๊ฒ€์ƒ‰์ฐฝ์—์„œ ssm๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ณ  [Systems Manager] ๋ฅผ ์„ ํƒ

  2. Systems Manager Dashboard ์™ผ์ชฝ ํŒจ๋„ Instances & Nodes ์„น์…˜ ์•„๋ž˜์— ์žˆ๋Š” [Session Manager] ์„ ํƒ

  3. [Start Session] โ†’ Instance Name: local-library-xxx ์„ ํƒ โ†’ [Start Session] ํด๋ฆญ

  4. Root ํ™˜๊ฒฝ์œผ๋กœ ์ „ํ™˜

    sudo -i
  5. Stress utility ์„ค์น˜

    yum install stress -y
  6. CPU load ์ƒ์„ฑ

    stress --cpu 4 --timeout 600
  7. ์‹ ๊ทœ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋˜๋Š”์ง€ ํ™•์ธ

Auto-healing ํ…Œ์ŠคํŠธ

  1. Session Manager๋ฅผ ํ†ตํ•ด์„œ EC2 ์ธ์Šคํ„ด์Šค์— ์ ‘์†

  2. Apache HTTP Server ์ •์ง€

    sudo service httpd stop
  3. ์ธ์Šคํ„ด์Šค๊ฐ€ ์ž๋™์œผ๋กœ ๋ณต๊ตฌ๋˜๋Š”์ง€ ํ™•์ธ ํ›„ Cloud9 IDE ์‹คํ–‰

  4. configuration ํŒŒ์ผ ์…์„ฑ

    touch .ebextensions/03_autoscaling.config
  5. .ebextensions/03_autoscaling.config ํŒŒ์ผ์„ ์—ด๊ณ  ์•„๋ž˜์˜ ์ฝ”๋“œ๋ธ”๋ก ๋ถ™์—ฌ๋„ฃ๊ธฐ

    Resources:
      AWSEBAutoScalingGroup:
        Type: "AWS::AutoScaling::AutoScalingGroup"
        Properties:
          HealthCheckType: ELB
          HealthCheckGracePeriod: 300
  6. ์ˆ˜์ •ํ•œ ์ฝ”๋“œ๋ฅผ Commit & Push

  7. ๋‹ค์‹œ EC2 ์ธ์Šคํ„ด์Šค์— ์ ‘์†ํ•ด์„œ Apache HTTP Server ์ •์ง€ํ•˜๊ณ  ๊ธฐ์กด ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒˆ๋กœ์šด ์ธ์Šคํ„ด์Šค๋กœ ๊ต์ฒด๋˜๋Š”์ง€ ํ™•์ธ

SSM Parameter Store ์„ค์ •

KMS ์•”ํ˜ธํ™” ํ‚ค ์ƒ์„ฑ

  1. AWS Management Console ์ขŒ์ธก ์ƒ๋‹จ์— ์žˆ๋Š” [Services] ๋ฅผ ์„ ํƒํ•˜๊ณ  ๊ฒ€์ƒ‰์ฐฝ์—์„œ kms๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ณ  [Key Management Service] ๋ฅผ ์„ ํƒ

  2. [Customer managed keys] โ†’ [Create key] โ†’ Key type = Symmetric โ†’ [Next] โ†’ Alias = eb โ†’ [Next] โ†’ Key administrators = ํ•ด๋‹น ์•”ํ˜ธํ™”ํ‚ค์— ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์„ ์ค„ IAM ์œ ์ € ์„ ํƒ โ†’ [Next] โ†’ This account ํƒญ์—์„œ eb-lab-IAMRole-xxxx๋ฅผ ์„ ํƒ โ†’ [Next] โ†’ [Finish]

SSM Parameter ์ƒ์„ฑ

  1. AWS Management Console ์ขŒ์ธก ์ƒ๋‹จ์— ์žˆ๋Š” [Services] ๋ฅผ ์„ ํƒํ•˜๊ณ  ๊ฒ€์ƒ‰์ฐฝ์—์„œ ssm๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ณ  [Systems Manager] ๋ฅผ ์„ ํƒ

  2. Systems Manager Dashboard ์™ผ์ชฝ ํŒจ๋„ Application Management ์„น์…˜ ์•„๋ž˜์— ์žˆ๋Š” [Parameter Store] ์„ ํƒ

  3. [Create parameter] โ†’ Name = /LOCAL_LIBRARY/DB_PASSWORD, Tier = Standard, Type = SecureString, KMS Key ID = alias/eb, Value = asdf1234 โ†’ [Create parameter]

IAM Role ๊ถŒํ•œ ์„ค์ •

  1. AWS Management Console์—์„œ ์ขŒ์ธก ์ƒ๋‹จ์— ์žˆ๋Š” [Services] ๋ฅผ ์„ ํƒํ•˜๊ณ  ๊ฒ€์ƒ‰์ฐฝ์—์„œ IAM๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ฑฐ๋‚˜ [Security, Identity, & Compliance] ๋ฐ”๋กœ ๋ฐ‘์— ์žˆ๋Š” [IAM] ๋ฅผ ์„ ํƒ

  2. [Roles] โ†’ eb-lab-IAMRole-xxxx๋ฅผ ์„ ํƒ

  3. [Add inline policy] ์„ ํƒ ํ›„, Service = Systems Manager, Actions = GetParameter, Resources = โœ… Specific โ†’ [Add ARN], Region = ap-northeast-2, Fully qualified parameter name = LOCAL_LIBRARY/DB_PASSWORD โ†’ [Add], [Review policy] ํด๋ฆญ, Name = ssm_get_param, [Create policy] ํด๋ฆญ

Application ์„ค์ • ํŒŒ์ผ ์ˆ˜์ •

  1. locallibrary/settings.py ํŒŒ์ผ์„ ์—ด๊ณ  DATABASES ๋ธ”๋ก ์œ„์— ์•„๋ž˜์˜ ์ฝ”๋“œ๋ธ”๋ก์„ ๋ถ™์—ฌ๋„ฃ๊ธฐ

    # SSM
    import boto3
    ## Create the SSM Client
    ssm = boto3.client(
        'ssm',
        region_name='ap-northeast-2'
    )
    
    ## Get the requested parameter
    response = ssm.get_parameter(
        Name='/LOCAL_LIBRARY/DB_PASSWORD',
        WithDecryption=True
    )
    
    DB_PASSWORD = response['Parameter']['Value']
  2. locallibrary/settings.py ํŒŒ์ผ์„ ์—ด๊ณ  DATABASES ๋ธ”๋ก์„ ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'local_library',
            'USER': 'local_library',
            'PASSWORD': DB_PASSWORD,
            'HOST': '<RDS_ENDPOINT>',
            'PORT': '5432',
        }
    }
  3. requirements.txtํŒŒ์ผ์„ ์—ด๊ณ  ์•„๋ž˜์˜ ๋ผ์ธ์„ ์ถ”๊ฐ€

    boto3==1.11.9
  4. ์ˆ˜์ •ํ•œ ์ฝ”๋“œ๋ฅผ Commit & Push

APM with X-Ray

  1. EB Dashboard์—์„œ [Configuration] โ†’ Category๊ฐ€ Software ์ธ ํƒญ์—์„œ [Modify] ํด๋ฆญ โ†’ X-Ray Daemon โœ… Enabled โ†’ [Apply]

    Elastic Beanstalk ํ™˜๊ฒฝ์— ๊ธฐ๋ณธ์œผ๋กœ X-Ray Daemon์ด ์„ค์น˜๋ฉ๋‹ˆ๋‹ค๋งŒ ์œ„์˜ ์˜ต์…˜์„ค์ •์œผ๋กœ ์‹คํ–‰์‹œ์ผœ์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค

  2. requirements.txtํŒŒ์ผ์„ ์—ด๊ณ  ์•„๋ž˜์˜ ๋ผ์ธ์„ ์ถ”๊ฐ€ (AWS X-Ray SDK for Python ์„ค์น˜)

    aws-xray-sdk==2.4.3
  3. locallibrary/settings.py ํŒŒ์ผ์„ ์—ด๊ณ  INSTALLED_APPS ๋ธ”๋ก์— aws_xray_sdk.ext.django ์ถ”๊ฐ€

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        # Add our new application
        'catalog.apps.CatalogConfig', #This object was created for us in /catalog/apps.py,
        'aws_xray_sdk.ext.django',
    ]
  4. locallibrary/settings.py ์—์„œ MIDDLEWARE ๋ธ”๋ก์— aws_xray_sdk.ext.django.middleware.XRayMiddleware ์ถ”๊ฐ€

    MIDDLEWARE = [
        'django.middleware.security.SecurityMiddleware',
        'whitenoise.middleware.WhiteNoiseMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
        'aws_xray_sdk.ext.django.middleware.XRayMiddleware',
    ]
  5. locallibrary/settings.py ์—์„œ ์•„๋ž˜์˜ ์ฝ”๋“œ๋ธ”๋ก์„ ๋ถ™์—ฌ๋„ฃ๊ธฐ

    XRAY_RECORDER = {
        'AWS_XRAY_DAEMON_ADDRESS': '127.0.0.1:2000',
        'AUTO_INSTRUMENT': True,  # If turned on built-in database queries and template rendering will be recorded as subsegments
        'AWS_XRAY_CONTEXT_MISSING': 'LOG_ERROR',
        'PLUGINS': (),
        'SAMPLING': True,
        'SAMPLING_RULES': None,
        'AWS_XRAY_TRACING_NAME': 'locallibrary', # the segment name for segments generated from incoming requests
        'DYNAMIC_NAMING': None, # defines a pattern that host names should match
        'STREAMING_THRESHOLD': None, # defines when a segment starts to stream out its children subsegments
    }
  6. IAM Dashboard๋กœ ์ด๋™ํ•ด์„œ eb-lab-IAMRole-xxxx์— AWSXRayWriteOnlyAccess ์ •์ฑ… ์—ฐ๊ฒฐ

  7. ์ˆ˜์ •ํ•œ ์ฝ”๋“œ๋ฅผ Commit & Push

  8. ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ ‘์† ํ›„ Browising

  9. AWS Management Console์—์„œ ์ขŒ์ธก ์ƒ๋‹จ์— ์žˆ๋Š” [Services] ๋ฅผ ์„ ํƒํ•˜๊ณ  ๊ฒ€์ƒ‰์ฐฝ์—์„œ X-Ray๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ฑฐ๋‚˜ [Developer Tools] ๋ฐ‘์— ์žˆ๋Š” [X-Ray] ๋ฅผ ์„ ํƒ

  10. X-Ray Dashboard์—์„œ [Traces] ์„ ํƒ

    • ๊ฐ URL๋ณ„ ์‘๋‹ต์†๋„ ํ™•์ธ
    • Trace list ์—์„œ Response Time ์ด ๊ฐ€์žฅ ๊ธด Trace๋ฅผ ์„ ํƒ ํ›„ Raw data ์—์„œ subsegments ํ™•์ธ