

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 사용자 지정 리소스 예제
<a name="customize-environment-resources-examples"></a>

다음 목록에는 Elastic Beanstalk 환경을 사용자 지정하는 데 사용할 수 있는 구성 파일의 예가 나열되어 있습니다.
+ [DynamoDB, CloudWatch 및 SNS](https://elasticbeanstalk.s3.amazonaws.com/extensions/DynamoDB-with-CloudWatch-Alarms.config)
+ [Elastic Load Balancing 및 CloudWatch](https://elasticbeanstalk.s3.amazonaws.com/extensions/ELB-Alarms.config)
+ [ElastiCache](https://elasticbeanstalk.s3.amazonaws.com/extensions/ElastiCache.config)
+ [RDS 및 CloudWatch](https://elasticbeanstalk.s3.amazonaws.com/extensions/RDS-Alarms.config)
+ [SQS, SNS 및 CloudWatch](https://elasticbeanstalk.s3.amazonaws.com/extensions/SNS.config)

이 페이지의 하위 항목에서는 Elastic Beanstalk 환경에서 사용자 지정 리소스를 추가하고 구성하기 위한 몇 가지 확장된 예를 제공합니다.

**Topics**
+ [예: ElastiCache](customize-environment-resources-elasticache.md)
+ [예: SQS, CloudWatch 및 SNS](customize-environment-resources-sqs.md)
+ [예: DynamoDB, CloudWatch, SNS](customize-environment-resources-dynamodb.md)

# 예: ElastiCache
<a name="customize-environment-resources-elasticache"></a>

다음 샘플은 EC2-Classic 및 EC2-VPC(기본 및 사용자 지정 [Amazon Virtual Private Cloud](https://docs.aws.amazon.com/vpc/latest/userguide/)(Amazon VPC)) 플랫폼에 Amazon ElastiCache 클러스터를 추가합니다. 이러한 플랫폼에 대한 자세한 내용과 EC2가 해당 리전 및 AWS 계정에 대해 지원하는 플랫폼을 결정하는 방법은 섹션을 참조하세요[https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-supported-platforms.html](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-supported-platforms.html). 그런 다음 사용 중인 플랫폼에 적용되는 이 주제의 단원을 참조하십시오.
+ [EC2-Classic 플랫폼](#customize-environment-resources-elasticache-classic)
+ [EC2-VPC(기본값)](#customize-environment-resources-elasticache-defaultvpc)
+ [EC2-VPC(사용자 지정)](#customize-environment-resources-elasticache-targetedvpc)

## EC2-Classic 플랫폼
<a name="customize-environment-resources-elasticache-classic"></a>

이 샘플은 EC2-Classic 플랫폼으로 시작된 인스턴스가 있는 환경에 Amazon ElastiCache 클러스터를 추가합니다. 이 예제에서 보이는 모든 속성은 이러한 각 리소스 유형에 대해 설정해야 하는 최소 필수 속성입니다. [ElastiCache 예제](https://elasticbeanstalk.s3.amazonaws.com/extensions/ElastiCache.config)에서 해당 예제를 다운로드할 수 있습니다.

**참고**  
이 예제에서는 요금이 부과될 수 있는 AWS 리소스를 생성합니다. AWS 요금에 대한 자세한 내용은 섹션을 참조하세요[https://aws.amazon.com/pricing/](https://aws.amazon.com/pricing/). 일부 서비스는 AWS 프리 티어의 일부입니다. 신규 고객은 무료로 이 서비스를 시험 사용할 수 있습니다. 자세한 정보는 [https://aws.amazon.com/free/](https://aws.amazon.com/free/)을 참조하세요.

이 예를 활용하려면 다음과 같이 하세요.

1. 소스 번들의 최상위 디렉터리에 `[.ebextensions](ebextensions.md)` 디렉터리를 생성합니다.

1. 확장자 `.config`로 구성 파일 두 개를 생성하고 `.ebextensions` 디렉터리로 가져옵니다. 구성 파일 하나는 리소스를 정의하고 다른 하나는 옵션을 정의합니다.

1. Elastic Beanstalk에 애플리케이션을 배포합니다.

   YAML은 일정한 들여쓰기를 사용합니다. 예제 구성 파일의 콘텐츠를 바꿀 때 들여쓰기 레벨을 일치시키고, 텍스트 편집기가 탭 문자 대신 공백을 사용해 들여쓰기를 하도록 합니다.

리소스를 정의하는 구성 파일(예: `elasticache.config`)을 생성합니다. 이 예제에서는 ElastiCache 클러스터 리소스(`MyElastiCache`)의 이름을 지정하고, 해당 리소스의 유형을 선언한 다음 클러스터의 속성을 구성하여 ElastiCache 클러스터를 생성합니다. 또한 이 구성 파일에서 생성 및 정의되는 ElastiCache 보안 그룹 리소스의 이름을 참조합니다. 다음으로 ElastiCache 보안 그룹을 생성합니다. 이 리소스의 이름을 정의하고, 리소스의 유형을 선언한 다음 보안 그룹에 대한 설명을 추가합니다. 마지막으로, ElastiCache 보안 그룹(`MyCacheSecurityGroup`) 및 Elastic Beanstalk 보안 그룹(`AWSEBSecurityGroup`) 내 인스턴스에서의 액세스만 허용하도록 ElastiCache 보안 그룹에 대한 수신 규칙을 설정합니다. 파라미터 이름 `AWSEBSecurityGroup`은 Elastic Beanstalk에서 제공하는 고정된 리소스 이름입니다. Elastic Beanstalk 애플리케이션에서 ElastiCache 클러스터의 인스턴스에 연결하도록 하려면 ElastiCache 보안 그룹 수신 규칙에 `AWSEBSecurityGroup`을 추가해야 합니다.

```
#This sample requires you to create a separate configuration file that defines the custom option settings for CacheCluster properties.
          
Resources:
  MyElastiCache:
    Type: AWS::ElastiCache::CacheCluster
    Properties:
      CacheNodeType: 
         Fn::GetOptionSetting:
             OptionName : CacheNodeType
             DefaultValue: cache.m1.small
      NumCacheNodes: 
           Fn::GetOptionSetting:
             OptionName : NumCacheNodes
             DefaultValue: 1
      Engine: 
           Fn::GetOptionSetting:
             OptionName : Engine
             DefaultValue: memcached
      CacheSecurityGroupNames:
        - Ref: MyCacheSecurityGroup
  MyCacheSecurityGroup:
    Type: AWS::ElastiCache::SecurityGroup
    Properties:
      Description: "Lock cache down to webserver access only"
  MyCacheSecurityGroupIngress:
    Type: AWS::ElastiCache::SecurityGroupIngress
    Properties:
      CacheSecurityGroupName: 
        Ref: MyCacheSecurityGroup
      EC2SecurityGroupName:
        Ref: AWSEBSecurityGroup
```

이 구성 파일 예제에서 사용된 리소스에 대한 자세한 내용은 다음 참조를 참조하십시오.
+ [AWS::ElastiCache::CacheCluster](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticache-cache-cluster.html)
+ [AWS::ElastiCache::SecurityGroup](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticache-security-group.html)
+ [AWS::ElastiCache:SecurityGroupIngress](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticache-security-group-ingress.html)

`options.config`라는 별개의 구성 파일을 생성하고, 사용자 지정 옵션 설정을 정의합니다.

```
option_settings:
  "aws:elasticbeanstalk:customoption":
     CacheNodeType : cache.m1.small
     NumCacheNodes : 1
     Engine : memcached
```

이러한 행은 사용할 실제 값의 이름-값 페어가 포함된 **aws:elasticbeanstalk:customoption** 섹션과 함께 option\$1settings 섹션이 포함된 구성 파일(이 예제의 options.config)의 **CacheNodeType, NumCacheNodes, and Engine** 값에서 **CacheNodeType, NumCacheNodes, and Engine** 속성의 값을 가져오라고 ElasticBeanstalk에 지시합니다. 위 예제에서 이는 cache.m1.small 즉, 1을 뜻하며 Memcached가 이 값에 사용됩니다. `Fn::GetOptionSetting`에 대한 자세한 정보는 [함수](ebextensions-functions.md) 섹션을 참조하세요.

## EC2-VPC(기본값)
<a name="customize-environment-resources-elasticache-defaultvpc"></a>

이 샘플은 EC2-VPC 플랫폼으로 시작된 인스턴스가 있는 환경에 Amazon ElastiCache 클러스터를 추가합니다. 특히, 이 섹션의 정보는 EC2가 인스턴스를 기본 VPC로 시작하는 시나리오에 적용됩니다. 이 예제의 모든 속성은 이러한 각 리소스 유형에 대해 설정해야 하는 최소 필수 속성입니다. 기본 VPC에 대한 자세한 내용은 [기본 VPC 및 서브넷](https://docs.aws.amazon.com/vpc/latest/userguide/default-vpc.html) 단원을 참조하세요.

**참고**  
이 예제에서는 요금이 부과될 수 있는 AWS 리소스를 생성합니다. AWS 요금에 대한 자세한 내용은 섹션을 참조하세요[https://aws.amazon.com/pricing/](https://aws.amazon.com/pricing/). 일부 서비스는 AWS 프리 티어의 일부입니다. 신규 고객은 무료로 이 서비스를 시험 사용할 수 있습니다. 자세한 정보는 [https://aws.amazon.com/free/](https://aws.amazon.com/free/)을 참조하세요.

이 예를 활용하려면 다음과 같이 하세요.

1. 소스 번들의 최상위 디렉터리에 `[.ebextensions](ebextensions.md)` 디렉터리를 생성합니다.

1. 확장자 `.config`로 구성 파일 두 개를 생성하고 `.ebextensions` 디렉터리로 가져옵니다. 구성 파일 하나는 리소스를 정의하고 다른 하나는 옵션을 정의합니다.

1. Elastic Beanstalk에 애플리케이션을 배포합니다.

   YAML은 일정한 들여쓰기를 사용합니다. 예제 구성 파일의 콘텐츠를 바꿀 때 들여쓰기 레벨을 일치시키고, 텍스트 편집기가 탭 문자 대신 공백을 사용해 들여쓰기를 하도록 합니다.

이제, 리소스 구성 파일의 이름을 `elasticache.config`로 지정합니다. ElastiCache 클러스터를 생성하기 위해 이 예제에서는 ElastiCache 클러스터 리소스(`MyElastiCache`)의 이름을 지정하고, 해당 리소스의 유형을 선언한 다음 클러스터의 속성을 구성합니다. 또한 이 구성 파일에서 생성 및 정의한 보안 그룹 리소스의 ID를 참조합니다.

다음으로 EC2 보안 그룹을 생성합니다. 리소스의 이름을 정의하고, 리소스의 유형을 선언한 다음 설명을 추가한 후 Elastic Beanstalk 보안 그룹(`AWSEBSecurityGroup`) 내 인스턴스에서의 액세스만 허용하도록 보안 그룹에 대한 수신 규칙을 설정합니다. (매개변수 이름 `AWSEBSecurityGroup`은 Elastic Beanstalk이 제공하는 고정형 리소스입니다. Elastic Beanstalk 애플리케이션에서 ElastiCache 클러스터의 인스턴스에 연결하도록 하려면 ElastiCache 보안 그룹 수신 규칙에 `AWSEBSecurityGroup`을 추가해야 합니다.)

또한 EC2 보안 그룹에 대한 수신 규칙은 캐시 노드가 연결을 수락할 수 있는 IP 프로토콜 및 포트 번호도 정의합니다. Redis용 기본 포트 번호는 `6379`입니다.

```
#This sample requires you to create a separate configuration file that defines the custom option settings for CacheCluster properties.

Resources:
  MyCacheSecurityGroup:
    Type: "AWS::EC2::SecurityGroup"
    Properties:
      GroupDescription: "Lock cache down to webserver access only"
      SecurityGroupIngress :
        - IpProtocol : "tcp"
          FromPort :
            Fn::GetOptionSetting:
              OptionName : "CachePort"
              DefaultValue: "6379"
          ToPort :
            Fn::GetOptionSetting:
              OptionName : "CachePort"
              DefaultValue: "6379"
          SourceSecurityGroupName:
            Ref: "AWSEBSecurityGroup"
  MyElastiCache:
    Type: "AWS::ElastiCache::CacheCluster"
    Properties:
      CacheNodeType:
        Fn::GetOptionSetting:
          OptionName : "CacheNodeType"
          DefaultValue : "cache.t2.micro"
      NumCacheNodes:
        Fn::GetOptionSetting:
          OptionName : "NumCacheNodes"
          DefaultValue : "1"
      Engine:
        Fn::GetOptionSetting:
          OptionName : "Engine"
          DefaultValue : "redis"
      VpcSecurityGroupIds:
        -
          Fn::GetAtt:
            - MyCacheSecurityGroup
            - GroupId

Outputs:
  ElastiCache:
    Description : "ID of ElastiCache Cache Cluster with Redis Engine"
    Value :
      Ref : "MyElastiCache"
```

이 구성 파일 예제에서 사용된 리소스에 대한 자세한 내용은 다음 참조를 참조하십시오.
+ [AWS::ElastiCache::CacheCluster](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticache-cache-cluster.html)
+ [AWS::EC2::SecurityGroup](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html)

다음으로, 옵션 구성 파일의 이름을 `options.config`로 지정하고, 사용자 지정 옵션 설정을 정의합니다.

```
option_settings:
  "aws:elasticbeanstalk:customoption":
    CacheNodeType : cache.t2.micro
    NumCacheNodes : 1
    Engine : redis
    CachePort : 6379
```

이러한 줄은 구성 파일(이 예제에서는 `options.config`)의 `CacheNodeType`, `NumCacheNodes`, `Engine` 및 `CachePort` 값에서 `CacheNodeType`, `NumCacheNodes`, `Engine` 및 `CachePort` 속성의 값을 가져오도록 Elastic Beanstalk에 지시합니다. 이 구성 파일에는 `aws:elasticbeanstalk:customoption` 아래에 사용할 실제 값이 들어 있는 이름-값 페어가 포함된 `option_settings` 섹션이 있습니다. 앞선 예제에서 `cache.t2.micro`, `1`, `redis` 및 `6379`이 이러한 값에 사용될 수 있습니다. `Fn::GetOptionSetting`에 대한 자세한 정보는 [함수](ebextensions-functions.md) 섹션을 참조하세요.

## EC2-VPC(사용자 지정)
<a name="customize-environment-resources-elasticache-targetedvpc"></a>

EC2-VPC 플랫폼에서 사용자 지정 VPC를 생성하고 이 VPC를 EC2에서 인스턴스를 시작할 VPC로 지정하면 환경에 Amazon ElastiCache 클러스터를 추가하는 프로세스가 기본 VPC의 프로세스와 달라집니다. ElastiCache 클러스터에 대한 서브넷 그룹을 생성해야 한다는 점이 가장 크게 다릅니다. 이 예제의 모든 속성은 이러한 각 리소스 유형에 대해 설정해야 하는 최소 필수 속성입니다.

**참고**  
이 예제에서는 요금이 부과될 수 있는 AWS 리소스를 생성합니다. AWS 요금에 대한 자세한 내용은 섹션을 참조하세요[https://aws.amazon.com/pricing/](https://aws.amazon.com/pricing/). 일부 서비스는 AWS 프리 티어의 일부입니다. 신규 고객은 무료로 이 서비스를 시험 사용할 수 있습니다. 자세한 정보는 [https://aws.amazon.com/free/](https://aws.amazon.com/free/)을 참조하세요.

이 예를 활용하려면 다음과 같이 하세요.

1. 소스 번들의 최상위 디렉터리에 `[.ebextensions](ebextensions.md)` 디렉터리를 생성합니다.

1. 확장자 `.config`로 구성 파일 두 개를 생성하고 `.ebextensions` 디렉터리로 가져옵니다. 구성 파일 하나는 리소스를 정의하고 다른 하나는 옵션을 정의합니다.

1. Elastic Beanstalk에 애플리케이션을 배포합니다.

   YAML은 일정한 들여쓰기를 사용합니다. 예제 구성 파일의 콘텐츠를 바꿀 때 들여쓰기 레벨을 일치시키고, 텍스트 편집기가 탭 문자 대신 공백을 사용해 들여쓰기를 하도록 합니다.

이제, 리소스 구성 파일의 이름을 `elasticache.config`로 지정합니다. ElastiCache 클러스터를 생성하기 위해 이 예제에서는 ElastiCache 클러스터 리소스(`MyElastiCache`)의 이름을 지정하고, 해당 리소스의 유형을 선언한 다음 클러스터의 속성을 구성합니다. 이 예제의 속성은 ElastiCache 클러스터의 서브넷 그룹 이름과 이 구성 파일에서 생성 및 정의한 보안 그룹 리소스의 ID를 참조합니다.

다음으로 EC2 보안 그룹을 생성합니다. 리소스의 이름을 정의하고, 리소스의 유형을 선언한 다음 설명 및 VPC ID를 추가한 후 Elastic Beanstalk 보안 그룹(`AWSEBSecurityGroup`) 내 인스턴스에서의 액세스만 허용하도록 보안 그룹에 대한 수신 규칙을 설정합니다. (매개변수 이름 `AWSEBSecurityGroup`은 Elastic Beanstalk이 제공하는 고정형 리소스입니다. Elastic Beanstalk 애플리케이션에서 ElastiCache 클러스터의 인스턴스에 연결하도록 하려면 ElastiCache 보안 그룹 수신 규칙에 `AWSEBSecurityGroup`을 추가해야 합니다.)

또한 EC2 보안 그룹에 대한 수신 규칙은 캐시 노드가 연결을 수락할 수 있는 IP 프로토콜 및 포트 번호도 정의합니다. Redis용 기본 포트 번호는 `6379`입니다. 마지막으로, 이 예제에서는 ElastiCache 클러스터의 서브넷 그룹을 생성합니다. 이 리소스의 이름을 정의하고, 리소스의 유형을 선언한 다음 서브넷 그룹의 서브넷 ID와 설명을 추가합니다.

**참고**  
ElastiCache 클러스터에 프라이빗 서브넷을 사용하는 것이 좋습니다. 프라이빗 서브넷을 사용하는 VPC에 대한 자세한 내용은 [https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Scenario2.html](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Scenario2.html) 단원을 참조하세요.

```
#This sample requires you to create a separate configuration file that defines the custom option settings for CacheCluster properties.

Resources:
  MyElastiCache:
    Type: "AWS::ElastiCache::CacheCluster"
    Properties:
      CacheNodeType:
        Fn::GetOptionSetting:
          OptionName : "CacheNodeType"
          DefaultValue : "cache.t2.micro"
      NumCacheNodes:
        Fn::GetOptionSetting:
          OptionName : "NumCacheNodes"
          DefaultValue : "1"
      Engine:
        Fn::GetOptionSetting:
          OptionName : "Engine"
          DefaultValue : "redis"
      CacheSubnetGroupName:
        Ref: "MyCacheSubnets"
      VpcSecurityGroupIds:
        - Ref: "MyCacheSecurityGroup"
  MyCacheSecurityGroup:
    Type: "AWS::EC2::SecurityGroup"
    Properties:
      GroupDescription: "Lock cache down to webserver access only"
      VpcId:
        Fn::GetOptionSetting:
          OptionName : "VpcId"
      SecurityGroupIngress :
        - IpProtocol : "tcp"
          FromPort :
            Fn::GetOptionSetting:
              OptionName : "CachePort"
              DefaultValue: "6379"
          ToPort :
            Fn::GetOptionSetting:
              OptionName : "CachePort"
              DefaultValue: "6379"
          SourceSecurityGroupId:
            Ref: "AWSEBSecurityGroup"
  MyCacheSubnets:
    Type: "AWS::ElastiCache::SubnetGroup"
    Properties:
      Description: "Subnets for ElastiCache"
      SubnetIds:
        Fn::GetOptionSetting:
          OptionName : "CacheSubnets"
Outputs:
  ElastiCache:
    Description : "ID of ElastiCache Cache Cluster with Redis Engine"
    Value :
      Ref : "MyElastiCache"
```

이 구성 파일 예제에서 사용된 리소스에 대한 자세한 내용은 다음 참조를 참조하십시오.
+ [AWS::ElastiCache::CacheCluster](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticache-cache-cluster.html)
+ [AWS::EC2::SecurityGroup](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html)
+ [AWS::ElastiCache::SubnetGroup](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticache-subnetgroup.html)

다음으로, 옵션 구성 파일의 이름을 `options.config`로 지정하고, 사용자 지정 옵션 설정을 정의합니다.

**참고**  
다음 예제에서는 고유한 서브넷 및 VPC로 예제 `CacheSubnets` 및 `VpcId` 값을 바꿉니다.

```
option_settings:
  "aws:elasticbeanstalk:customoption":
    CacheNodeType : cache.t2.micro
    NumCacheNodes : 1
    Engine : redis
    CachePort : 6379
    CacheSubnets:
      - subnet-1a1a1a1a
      - subnet-2b2b2b2b
      - subnet-3c3c3c3c
    VpcId: vpc-4d4d4d4d
```

이러한 줄은 구성 파일(이 예제에서는 `options.config`)의 `CacheNodeType`, `NumCacheNodes`, `Engine`, `CachePort`, `CacheSubnets` 및 `VpcId` 값에서 `CacheNodeType`, `NumCacheNodes`, `Engine`, `CachePort`, `CacheSubnets` 및 `VpcId` 속성의 값을 가져오도록 Elastic Beanstalk에 지시합니다. 이 구성 파일에는 `aws:elasticbeanstalk:customoption` 아래에 샘플 값이 들어 있는 이름-값 페어가 포함된 `option_settings` 섹션이 있습니다. 위의 예제에서 `cache.t2.micro`, `1`, `redis`, `6379`, `subnet-1a1a1a1a`, `subnet-2b2b2b2b`, `subnet-3c3c3c3c` 및 `vpc-4d4d4d4d`이 이러한 값에 사용될 수 있습니다. `Fn::GetOptionSetting`에 대한 자세한 정보는 [함수](ebextensions-functions.md) 섹션을 참조하세요.

# 예: SQS, CloudWatch 및 SNS
<a name="customize-environment-resources-sqs"></a>

이 예제에서는 환경에 Amazon SQS 대기열과 대기열 깊이에 대한 경보를 추가합니다. 이 예제에서 보이는 속성은 이러한 각 리소스에 대해 설정해야 하는 최소 필수 속성입니다. [SQS, SNS, CloudWatch](https://elasticbeanstalk.s3.amazonaws.com/extensions/SNS.config)에서 예제를 다운로드할 수 있습니다.

**참고**  
이 예제에서는 요금이 부과될 수 있는 AWS 리소스를 생성합니다. AWS 요금에 대한 자세한 내용은 섹션을 참조하세요[https://aws.amazon.com/pricing/](https://aws.amazon.com/pricing/). 일부 서비스는 AWS 프리 티어의 일부입니다. 신규 고객은 무료로 이 서비스를 시험 사용할 수 있습니다. 자세한 정보는 [https://aws.amazon.com/free/](https://aws.amazon.com/free/)을 참조하세요.

이 예를 활용하려면 다음과 같이 하세요.

1. 소스 번들의 최상위 디렉터리에 `[.ebextensions](ebextensions.md)` 디렉터리를 생성합니다.

1. 확장자 `.config`로 구성 파일 두 개를 생성하고 `.ebextensions` 디렉터리로 가져옵니다. 구성 파일 하나는 리소스를 정의하고 다른 하나는 옵션을 정의합니다.

1. Elastic Beanstalk에 애플리케이션을 배포합니다.

   YAML은 일정한 들여쓰기를 사용합니다. 예제 구성 파일의 콘텐츠를 바꿀 때 들여쓰기 레벨을 일치시키고, 텍스트 편집기가 탭 문자 대신 공백을 사용해 들여쓰기를 하도록 합니다.

리소스를 정의하는 구성 파일(예: sqs.config)을 생성합니다. 이 예제에서는 SQS 대기열을 만들고 `VisbilityTimeout` 리소스의 `MySQSQueue` 속성을 정의합니다. 그런 다음 SNS `Topic`을 만들고 경보가 울리면 이메일을 `someone@example.com`으로 보내도록 지정합니다. 마지막으로 대기열이 메시지 10개 이상으로 증가하면 CloudWatch 경보를 생성합니다. `Dimensions` 속성에서 차원 측정을 나타내는 차원 이름과 값을 지정합니다. `Fn::GetAtt`를 사용하여 `QueueName`에서 `MySQSQueue`의 값을 반환합니다.

```
#This sample requires you to create a separate configuration file to define the custom options for the SNS topic and SQS queue.
Resources:
  MySQSQueue:
    Type: AWS::SQS::Queue
    Properties: 
      VisibilityTimeout:
        Fn::GetOptionSetting:
          OptionName: VisibilityTimeout
          DefaultValue: 30
  AlarmTopic:
    Type: AWS::SNS::Topic
    Properties: 
      Subscription:
        - Endpoint:
            Fn::GetOptionSetting:
              OptionName: AlarmEmail
              DefaultValue: "nobody@amazon.com"
          Protocol: email
  QueueDepthAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmDescription: "Alarm if queue depth grows beyond 10 messages"
      Namespace: "AWS/SQS"
      MetricName: ApproximateNumberOfMessagesVisible
      Dimensions:
        - Name: QueueName
          Value : { "Fn::GetAtt" : [ "MySQSQueue", "QueueName"] }
      Statistic: Sum
      Period: 300
      EvaluationPeriods: 1
      Threshold: 10
      ComparisonOperator: GreaterThanThreshold
      AlarmActions:
        - Ref: AlarmTopic
      InsufficientDataActions:
        - Ref: AlarmTopic

Outputs :
  QueueURL: 
    Description : "URL of newly created SQS Queue"
    Value : { Ref : "MySQSQueue" }
  QueueARN :
    Description : "ARN of newly created SQS Queue"
    Value : { "Fn::GetAtt" : [ "MySQSQueue", "Arn"]}
  QueueName :
    Description : "Name newly created SQS Queue"
    Value : { "Fn::GetAtt" : [ "MySQSQueue", "QueueName"]}
```

이 구성 파일 예제에서 사용된 리소스에 대한 자세한 내용은 다음 참조를 참조하십시오.
+ [AWS::SQS::Queue](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html)
+ [AWS::SNS::Topic](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sns-topic.html)
+ [AWS::CloudWatch::Alarm](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html)

`options.config`라는 별개의 구성 파일을 생성하고, 사용자 지정 옵션 설정을 정의합니다.

```
option_settings:
  "aws:elasticbeanstalk:customoption":
     VisibilityTimeout : 30
     AlarmEmail : "nobody@example.com"
```

이러한 행은 사용할 실제 값의 이름-값 페어가 포함된 **aws:elasticbeanstalk:customoption** 섹션과 함께 option\$1settings 섹션이 포함된 구성 파일(이 예제의 options.config)의 **VisibilityTimeout and Subscription Endpoint** 값에서 **VisibilityTimeout and Subscription Endpoint** 속성의 값을 가져오라고 Elastic Beanstalk에 지시합니다. 위 예제에서 이는 30을 뜻하며 "nobody@amazon.com"이 값에 사용됩니다. `Fn::GetOptionSetting`에 대한 자세한 정보는 [함수](ebextensions-functions.md) 섹션을 참조하세요.

# 예: DynamoDB, CloudWatch, SNS
<a name="customize-environment-resources-dynamodb"></a>

이 구성 파일은 PHP 2용 AWS SDK를 사용하여 DynamoDB 테이블을 PHP 기반 애플리케이션의 세션 핸들러로 설정합니다. 이 예를 사용하려면 환경의 인스턴스에 추가되고 DynamoDB 테이블에 액세스하는 데 사용하는 IAM 인스턴스 프로파일이 있어야 합니다.

 [DynamoDB 세션 지원 예제](https://elasticbeanstalk.s3.amazonaws.com/extensions/PHP-DynamoDB-Session-Support.zip)에서 이 단계에서 사용할 샘플을 다운로드할 수 있습니다. 샘플에는 다음 파일이 들어 있습니다.
+ 샘플 애플리케이션인 `index.php`
+ DynamoDB 테이블 및 기타 AWS 리소스를 생성 및 구성하고 Elastic Beanstalk 환경에서 애플리케이션을 호스팅하는 EC2 인스턴스에 소프트웨어를 설치`dynamodb.config`하기 위한 구성 파일
+ `options.config` 구성 파일 - 이 특정 설치의 특정 설정으로 `dynamodb.config`의 기본값 재정의

**`index.php`**

```
<?php

// Include the SDK using the Composer autoloader
require '../vendor/autoload.php';

use Aws\DynamoDb\DynamoDbClient;

// Grab the session table name and region from the configuration file
list($tableName, $region) = file(__DIR__ . '/../sessiontable');
$tableName = rtrim($tableName);
$region = rtrim($region);

// Create a DynamoDB client and register the table as the session handler
$dynamodb = DynamoDbClient::factory(array('region' => $region));
$handler = $dynamodb->registerSessionHandler(array('table_name' => $tableName, 'hash_key' => 'username'));

// Grab the instance ID so we can display the EC2 instance that services the request
$instanceId = file_get_contents("http://169.254.169.254/latest/meta-data/instance-id");
?>
<h1>Elastic Beanstalk PHP Sessions Sample</h1>
<p>This sample application shows the integration of the Elastic Beanstalk PHP
container and the session support for DynamoDB from the AWS SDK for PHP 2.
Using DynamoDB session support, the application can be scaled out across
multiple web servers. For more details, see the
<a href="https://aws.amazon.com/php/">PHP Developer Center</a>.</p>

<form id="SimpleForm" name="SimpleForm" method="post" action="index.php">
<?php
echo 'Request serviced from instance ' . $instanceId . '<br/>';
echo '<br/>';

if (isset($_POST['continue'])) {
  session_start();
  $_SESSION['visits'] = $_SESSION['visits'] + 1;
  echo 'Welcome back ' . $_SESSION['username'] . '<br/>';
  echo 'This is visit number ' . $_SESSION['visits'] . '<br/>';
  session_write_close();
  echo '<br/>';
  echo '<input type="Submit" value="Refresh" name="continue" id="continue"/>';
  echo '<input type="Submit" value="Delete Session" name="killsession" id="killsession"/>';
} elseif (isset($_POST['killsession'])) {
  session_start();
  echo 'Goodbye ' . $_SESSION['username'] . '<br/>';
  session_destroy();
  echo 'Username: <input type="text" name="username" id="username" size="30"/><br/>';
  echo '<br/>';
  echo '<input type="Submit" value="New Session" name="newsession" id="newsession"/>';
} elseif (isset($_POST['newsession'])) {
  session_start();
  $_SESSION['username'] = $_POST['username'];
  $_SESSION['visits'] = 1;
  echo 'Welcome to a new session ' . $_SESSION['username'] . '<br/>';
  session_write_close();
  echo '<br/>';
  echo '<input type="Submit" value="Refresh" name="continue" id="continue"/>';
  echo '<input type="Submit" value="Delete Session" name="killsession" id="killsession"/>';
} else {
  echo 'To get started, enter a username.<br/>';
  echo '<br/>';
  echo 'Username: <input type="text" name="username" id="username" size="30"/><br/>';
  echo '<input type="Submit" value="New Session" name="newsession" id="newsession"/>';
}
?>
</form>
```

**`.ebextensions/dynamodb.config`**

```
Resources:
  SessionTable:
    Type: AWS::DynamoDB::Table
    Properties:
      KeySchema: 
        HashKeyElement:
          AttributeName:
            Fn::GetOptionSetting:
              OptionName : SessionHashKeyName
              DefaultValue: "username"
          AttributeType:
            Fn::GetOptionSetting:
              OptionName : SessionHashKeyType
              DefaultValue: "S"
      ProvisionedThroughput:
        ReadCapacityUnits:
          Fn::GetOptionSetting:
            OptionName : SessionReadCapacityUnits
            DefaultValue: 1
        WriteCapacityUnits:
          Fn::GetOptionSetting:
            OptionName : SessionWriteCapacityUnits
            DefaultValue: 1

  SessionWriteCapacityUnitsLimit:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, " write capacity limit on the session table." ]]}
      Namespace: "AWS/DynamoDB"
      MetricName: ConsumedWriteCapacityUnits
      Dimensions:
        - Name: TableName
          Value: { "Ref" : "SessionTable" }
      Statistic: Sum
      Period: 300
      EvaluationPeriods: 12
      Threshold:
          Fn::GetOptionSetting:
            OptionName : SessionWriteCapacityUnitsAlarmThreshold
            DefaultValue: 240
      ComparisonOperator: GreaterThanThreshold
      AlarmActions:
        - Ref: SessionAlarmTopic
      InsufficientDataActions:
        - Ref: SessionAlarmTopic

  SessionReadCapacityUnitsLimit:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, " read capacity limit on the session table." ]]}
      Namespace: "AWS/DynamoDB"
      MetricName: ConsumedReadCapacityUnits
      Dimensions:
        - Name: TableName
          Value: { "Ref" : "SessionTable" }
      Statistic: Sum
      Period: 300
      EvaluationPeriods: 12
      Threshold:
          Fn::GetOptionSetting:
            OptionName : SessionReadCapacityUnitsAlarmThreshold
            DefaultValue: 240
      ComparisonOperator: GreaterThanThreshold
      AlarmActions:
        - Ref: SessionAlarmTopic
      InsufficientDataActions:
        - Ref: SessionAlarmTopic

  SessionThrottledRequestsAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, ": requests are being throttled." ]]}
      Namespace: AWS/DynamoDB
      MetricName: ThrottledRequests
      Dimensions:
        - Name: TableName
          Value: { "Ref" : "SessionTable" }
      Statistic: Sum
      Period: 300
      EvaluationPeriods: 1
      Threshold: 
        Fn::GetOptionSetting:
          OptionName: SessionThrottledRequestsThreshold
          DefaultValue: 1
      ComparisonOperator: GreaterThanThreshold
      AlarmActions:
        - Ref: SessionAlarmTopic
      InsufficientDataActions:
        - Ref: SessionAlarmTopic

  SessionAlarmTopic:
    Type: AWS::SNS::Topic
    Properties:
      Subscription:
        - Endpoint:
            Fn::GetOptionSetting:
              OptionName: SessionAlarmEmail
              DefaultValue: "nobody@amazon.com"
          Protocol: email

files:
  "/var/app/sessiontable":
    mode: "000444"
    content: |
      `{"Ref" : "SessionTable"}`
      `{"Ref" : "AWS::Region"}`

  "/var/app/composer.json":
    mode: "000744"
    content:
      {
        "require": {
           "aws/aws-sdk-php": "*"
        }
      }

container_commands:
 "1-install-composer":
   command: "cd /var/app; curl -s http://getcomposer.org/installer | php"
 "2-install-dependencies":
   command: "cd /var/app; php composer.phar install"
 "3-cleanup-composer":
   command: "rm -Rf /var/app/composer.*"
```

샘플 구성 파일에서는 먼저 DynamoDB 테이블을 만든 후 충분한 리소스를 할당하도록 테이블과 용량 단위의 기본 키 구조를 구성하여 요청한 처리량을 제공합니다. 그런 다음 `WriteCapacity` 및 `ReadCapacity`에 대한 CloudWatch 경보를 만듭니다. 경보 임계값을 초과하면 "nobody@amazon.com"에 이메일을 보내는 SNS 주제를 만듭니다.

환경을 위한 AWS 리소스를 생성하고 구성한 후에는 EC2 인스턴스를 사용자 지정해야 합니다. `files` 키를 사용하여 DynamoDB 테이블의 세부 정보를 환경의 EC2 인스턴스에 전달하고 AWS SDK for PHP 2 `composer.json` 파일에 "필수"를 추가합니다. 마지막으로 컨테이너 명령을 실행하여 composer와 필요한 종속 항목을 설치한 후 설치 관리자를 제거합니다.

**`.ebextensions/options.config`**

```
option_settings:
  "aws:elasticbeanstalk:customoption":
     SessionHashKeyName                      : username
     SessionHashKeyType                      : S
     SessionReadCapacityUnits                : 1
     SessionReadCapacityUnitsAlarmThreshold  : 240
     SessionWriteCapacityUnits               : 1 
     SessionWriteCapacityUnitsAlarmThreshold : 240
     SessionThrottledRequestsThreshold       : 1
     SessionAlarmEmail                       : me@example.com
```

SessionAlarmEmail 값을 경보 알림을 보내고자 하는 이메일로 바꿉니다. `options.config` 파일에는 `dynamodb.config`에서 정의된 일부 변수에 사용되는 값이 들어 있습니다. 예를 들어 `dynamodb.config`에는 다음 줄이 포함되어 있습니다.

```
Subscription:
  - Endpoint:
      Fn::GetOptionSetting:
        OptionName: SessionAlarmEmail
        DefaultValue: "nobody@amazon.com"
```

이러한 행은 사용할 실제 값의 이름-값 페어가 포함된 **aws:elasticbeanstalk:customoption** 섹션과 함께 option\$1settings 섹션이 포함된 구성 파일(샘플 애플리케이션의 `options.config`)의 **SessionAlarmEmail** 값에서 **엔드포인트** 속성의 값을 가져오라고 Elastic Beanstalk에 지시합니다. 위 예에서 이는 **SessionAlarmEmail**이 값 `nobody@amazon.com`을 할당할 것임을 의미합니다.

이 예에서 사용된 CloudFormation 리소스에 대한 자세한 내용은 다음 참조를 참조하십시오.
+ [AWS::DynamoDB::Table](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html)
+ [AWS::CloudWatch::Alarm](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html)
+ [AWS::SNS::Topic](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sns-topic.html)