

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

# AWS SAM 템플릿의 글로벌 섹션
<a name="sam-specification-template-anatomy-globals"></a>

 AWS SAM 템플릿에서 선언하는 리소스에 공통 구성이 있는 경우가 있습니다. 예를 들어 동일한 `AWS::Serverless::Function`, `Runtime`, `Memory`, `VPCConfig` 및 `Environment`의 구성을 갖는 여러 `Cors` 리소스가 있는 애플리케이션이 있을 수 있습니다. 모든 리소스에서 이 정보를 복제하는 대신 `Globals` 섹션에서 정보를 한 번 선언하고 리소스가 해당 정보를 승계하도록 할 수 있습니다.

`Globals` 섹션은 다음 AWS SAM 리소스 유형을 지원합니다.
+ `AWS::Serverless::Api`
+ `AWS::Serverless::CapacityProvider`
+ `AWS::Serverless::Function`
+ `AWS::Serverless::HttpApi`
+ `AWS::Serverless::SimpleTable`
+ `AWS::Serverless::StateMachine`

예제:

```
Globals:
  Function:
    Runtime: nodejs12.x
    Timeout: 180
    Handler: index.handler
    Environment:
      Variables:
        TABLE_NAME: data-table

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
        Variables:
          MESSAGE: "Hello From SAM"

  ThumbnailFunction:
    Type: AWS::Serverless::Function
    Properties:
      Events:
        Thumbnail:
          Type: Api
          Properties:
            Path: /thumbnail
            Method: POST
```

이 예제에서는 `HelloWorldFunction` 및 `ThumbnailFunction` 둘 다 `Runtime`을 위하여 “nodejs12.x”, `Timeout`를 위하여 “180”초, `Handler`를 위하여 “index.handler”를 각각 사용합니다. `HelloWorldFunction`은 승계된 TABLE\_NAME 외에도 메시지 환경 변수를 추가합니다. `ThumbnailFunction`은 모든 `Globals` 속성을 승계하고 API 이벤트 소스를 추가합니다.

## 지원되는 리소스 및 속성
<a name="sam-specification-template-anatomy-globals-supported-resources-and-properties"></a>

AWS SAM 는 다음 리소스 및 속성을 지원합니다.

```
Globals:
  Api:
    AccessLogSetting:
    Auth:
    BinaryMediaTypes:
    CacheClusterEnabled:
    CacheClusterSize:
    CanarySetting:
    Cors:
    DefinitionUri:
    Domain:
    EndpointConfiguration:
    EndpointAccessMode:
    GatewayResponses:
    MethodSettings:
    MinimumCompressionSize:
    Name:
    OpenApiVersion:
    PropagateTags:
    SecurityPolicy:
    TracingEnabled:
    Variables:
  
  CapacityProvider:
    InstanceRequirements:
    KmsKeyArn:
    OperatorRole:
    PropagateTags:
    ScalingConfig:
    Tags:
    VpcConfig:
  
  Function:
    Architectures:
    AssumeRolePolicyDocument:
    AutoPublishAlias:
    AutoPublishAliasAllProperties:
    CapacityProviderConfig:
    CodeSigningConfigArn:
    CodeUri:
    DeadLetterQueue:
    DeploymentPreference:
    Description:
    DurableConfig:
    Environment:
    EphemeralStorage:
    EventInvokeConfig:
    FileSystemConfigs:
    FunctionScalingConfig:
    FunctionUrlConfig:
    Handler:
    KmsKeyArn:
    Layers:
    LoggingConfig:
    MemorySize:
    PermissionsBoundary:
    PropagateTags:
    ProvisionedConcurrencyConfig:
    PublishToLatestPublished:
    RecursiveLoop:
    ReservedConcurrentExecutions:
    RolePath:
    Runtime:
    RuntimeManagementConfig:
    SnapStart:
    SourceKMSKeyArn:
    Tags:
    TenancyConfig:
    Timeout:
    Tracing:
    VersionDeletionPolicy:
    VpcConfig:

  HttpApi:
    AccessLogSettings:
    Auth:
    PropagateTags:
    StageVariables:
    Tags:

  SimpleTable:
    SSESpecification:
    
  StateMachine:
    PropagateTags:
```

**참고**  
이전 목록에 없는 리소스 및 속성은 일체 지원되지 않습니다. 지원되지 않는 몇 가지 이유는 다음과 같습니다. 1) 이들이 잠재적 보안 문제를 야기하거나 2) 이들이 템플릿을 이해하기 어렵게 만듭니다.

## 묵시적 API
<a name="sam-specification-template-anatomy-globals-implicit-apis"></a>

AWS SAM 는 `Events` 섹션에서 * APIs를 선언할 때 암시적* API를 생성합니다. `Globals`을 사용하여 묵시적 API의 모든 속성을 재설정할 수 있습니다.

## 재설정 가능한 속성
<a name="sam-specification-template-anatomy-globals-overrideable"></a>

리소스는 `Globals` 섹션에서 선언한 속성을 재설정할 수 있습니다. 예를 들어 환경 변수 맵에 새 변수를 추가하거나 전역적으로 선언된 변수를 재설정할 수 있습니다. 하지만 리소스는 `Globals` 섹션에 지정된 속성을 제거할 수 없습니다.

보다 일반적으로 `Globals` 섹션은 모든 리소스가 공유하는 속성을 선언합니다. 일부 리소스는 전역적으로 선언된 속성에 새 값을 제공할 수 있지만 제거할 수는 없습니다. 일부 리소스는 속성을 사용하지만 다른 리소스는 사용하지 않는 경우 `Globals` 섹션에서 속성을 선언해서는 안 됩니다.

다음 단원에서는 데이터 유형별로 재설정이 작동하는 방식을 설명합니다.

### 기본 데이터 유형 대체됨
<a name="sam-specification-template-anatomy-globals-overrideable-primitives"></a>

기본 데이터 유형에는 문자열, 숫자, 부울 등이 포함됩니다.

`Resources` 섹션에 지정된 값이 `Globals` 섹션의 값을 대체합니다. 

예제:

```
Globals:
  Function:
    Runtime: nodejs12.x

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: python3.9
```

`Runtime`에 대한 `MyFunction`은 `python3.9`으로 설정됩니다.

### 맵 병합됨
<a name="sam-specification-template-anatomy-globals-overrideable-maps"></a>

맵은 사전 또는 키-값 페어의 모음이라고도 합니다.

`Resources` 섹션의 맵 항목은 글로벌 맵 항목과 병합됩니다. 중복된 항목이 있는 경우 `Resource` 섹션 항목이 `Globals` 섹션 항목에 우선합니다. 

예제:

```
Globals:
  Function:
    Environment:
      Variables:
        STAGE: Production
        TABLE_NAME: global-table

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
        Variables:
          TABLE_NAME: resource-table
          NEW_VAR: hello
```

`MyFunction`의 환경 변수는 다음과 같이 설정됩니다.

```
{
  "STAGE": "Production",
  "TABLE_NAME": "resource-table",
  "NEW_VAR": "hello"
}
```

### 목록 추가 기능
<a name="sam-specification-template-anatomy-globals-overrideable-lists"></a>

리스트는 배열이라고도 합니다.

`Globals` 섹션의 목록 항목은 `Resources` 섹션의 목록 앞에 추가됩니다.

예제:

```
Globals:
  Function:
    VpcConfig:
      SecurityGroupIds:
        - sg-123
        - sg-456

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      VpcConfig:
        SecurityGroupIds:
          - sg-first
```

`SecurityGroupIds`의 `MyFunction`을 위한 `VpcConfig` 양식은 다음과 같이 설정됩니다.

```
[ "sg-123", "sg-456", "sg-first" ]
```