

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

# 에 대한 리소스 정책 예제 AWS SAM
<a name="serverless-controlling-access-to-apis-resource-policies"></a>

귀하의 AWS SAM 템플릿 내에 리소스 정책을 연결하여 API에 대한 액세스를 제어할 수 있습니다. 이 작업을 수행하려면 [ApiAuth](sam-property-api-apiauth.md) 데이터 유형을 사용합니다. 

다음은 프라이빗 API의 예제 AWS SAM 템플릿입니다. 프라이빗 API에는 배포할 리소스 정책이 있어야 합니다.

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  MyPrivateApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      EndpointConfiguration: PRIVATE  # Creates a private API. Resource policies are required for all private APIs.
      Auth:
        ResourcePolicy:
          CustomStatements: 
            - Effect: 'Allow'
              Action: 'execute-api:Invoke'
              Resource: ['execute-api:/*/*/*']
              Principal: '*'
            - Effect: 'Deny'
              Action: 'execute-api:Invoke'
              Resource: ['execute-api:/*/*/*']
              Principal: '*'
  MyFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      InlineCode: |
        def handler(event, context):
          return {'body': 'Hello World!', 'statusCode': 200}
      Handler: index.handler
      Runtime: python3.10
      Events:
        AddItem:
          Type: Api
          Properties:
            RestApiId: 
              Ref: MyPrivateApi
            Path: /
            Method: get
```

리소스 정책에 대한 자세한 내용은 *API Gateway 개발자 안내서*의 [API Gateway 리소스 정책을 사용하는 액세스 제어](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies.html)를 참조하세요. 프라이빗 API에 대한 자세한 내용은 API Gateway 개발자 안내서**의 [Amazon API Gateway에서 프라이빗 API 생성](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-private-apis.html)을 참조하세요.