

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

# CloudWatch Application Insights를 사용하여 AWS SAM 서버리스 애플리케이션 모니터링
<a name="monitor-app-insights"></a>

 Amazon CloudWatch Application Insights는 애플리케이션의 AWS 리소스를 모니터링하여 잠재적 문제를 식별하는 데 도움이 됩니다. AWS 리소스 데이터를 분석하여 문제의 징후를 확인하고 자동화된 대시보드를 구축하여 시각화할 수 있습니다. AWS Serverless Application Model (AWS SAM) 애플리케이션과 함께 사용하도록 CloudWatch Application Insights를 구성할 수 있습니다. CloudWatch Application Insights에 대한 자세한 내용은 *Amazon CloudWatch 사용자 가이드*의 [Amazon CloudWatch Application Insights](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html)를 잠조하세요.

**Topics**
+ [를 사용하여 CloudWatch Application Insights 구성 AWS SAM](#monitor-app-insights-configure)
+ [다음 단계](#monitor-app-insights-next)

## 를 사용하여 CloudWatch Application Insights 구성 AWS SAM
<a name="monitor-app-insights-configure"></a>

 AWS SAM 명령줄 인터페이스(AWS SAM CLI) 또는 AWS SAM 템플릿을 통해 AWS SAM 애플리케이션에 대한 CloudWatch Application Insights를 구성합니다.

### AWS SAMCLI을 통해 구성하십시오.
<a name="monitor-app-insights-configure-cli"></a>

 **sam init**을 사용하여 애플리케이션을 초기화할 때는 대화형 흐름을 통해 또는 **--application-insights** 옵션을 사용하여 CloudWatch Application Insights를 활성화하십시오.

 AWS SAMCLI 대화형 흐름을 통해 CloudWatch Application Insights를 활성화하려면 프롬프트가 표시될 때 **y**을 입력합니다.

```
Would you like to enable monitoring using CloudWatch Application Insights?
For more info, please view https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html [y/N]:
```

 **--application-insights** 옵션을 사용하여 CloudWatch Application Insights를 활성화하려면 다음과 같이 하십시오.

```
sam init --application-insights
```

 **sam init** 명령의 사용에 대한 자세한 내용은 [sam init](sam-cli-command-reference-sam-init.md)를 잠조하세요.

### AWS SAM 템플릿을 통해 구성
<a name="monitor-app-insights-configure-template"></a>

 AWS SAM 템플릿에서 `AWS::ResourceGroups::Group` 및 `AWS::ApplicationInsights::Application` 리소스를 정의하여 CloudWatch Application Insights를 활성화합니다.

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31 
...
Resources:
  ApplicationResourceGroup:
    Type: AWS::ResourceGroups::Group
    Properties:
      Name:
        Fn::Join:
        - ''
        - - ApplicationInsights-SAM-
        - Ref: AWS::StackName
      ResourceQuery:
        Type: CLOUDFORMATION_STACK_1_0
  ApplicationInsightsMonitoring:
    Type: AWS::ApplicationInsights::Application
    Properties:
      ResourceGroupName:
        Fn::Join:
          - ''
          - - ApplicationInsights-SAM-
          - Ref: AWS::StackName
        AutoConfigurationEnabled: 'true'
    DependsOn: ApplicationResourceGroup
```
+  `AWS::ResourceGroups::Group` - 한 번에 많은 AWS 리소스에 대한 작업을 관리하고 자동화하기 위해 리소스를 구성하는 그룹을 생성합니다. 여기에서 CloudWatch Application Insights와 함께 사용할 리소스 그룹을 생성합니다. 이러한 리소스 유형에 대한 자세한 내용은 *AWS CloudFormation 사용자 가이드*의 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-resourcegroups-group.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-resourcegroups-group.html)를 잠조하세요.
+  `AWS::ApplicationInsights::Application` – 리소스 그룹에 대하여 CloudWatch Application Insights를 구성합니다. 이러한 리소스 유형에 대한 자세한 내용은 *AWS CloudFormation 사용자 가이드*의 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-applicationinsights-application.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-applicationinsights-application.html)를 잠조하세요.

 두 리소스 모두 애플리케이션 배포 CloudFormation 시에 자동으로 전달됩니다. AWS SAM 템플릿의 CloudFormation 구문을 사용하여 CloudWatch Application Insights를 추가로 구성할 수 있습니다. 자세한 내용은 *Amazon CloudWatch 사용 설명서*의 [CloudFormation 템플릿 사용을](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/appinsights-cloudformation.html) 참조하세요.

 **sam init --application-insights** 명령을 사용하면 템플릿에 이러한 리소스가 모두 자동으로 생성됩니다 AWS SAM . 다음은 생성된 템플릿의 예입니다.

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  sam-app-test
  
  Sample SAM Template for sam-app-test

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 3
    MemorySize: 128

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.9
      Architectures:
      - x86_64
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello
            Method: get

  ApplicationResourceGroup:
    Type: AWS::ResourceGroups::Group
    Properties:
      Name:
        Fn::Join:
        - ''
        - - ApplicationInsights-SAM-
        - Ref: AWS::StackName
      ResourceQuery:
      	Type: CLOUDFORMATION_STACK_1_0
  ApplicationInsightsMonitoring:
    Type: AWS::ApplicationInsights::Application
    Properties:
      ResourceGroupName:
        Fn::Join:
        - ''
        - - ApplicationInsights-SAM-
        - Ref: AWS::StackName
      AutoConfigurationEnabled: 'true'
    DependsOn: ApplicationResourceGroup
    
Outputs:
  # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
  # Find out more about other implicit resources you can reference within SAM
  # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
  HelloWorldApi:
    Description: API Gateway endpoint URL for Prod stage for Hello World function
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
  HelloWorldFunction:
    Description: Hello World Lambda Function ARN
    Value: !GetAtt HelloWorldFunction.Arn
  HelloWorldFunctionIamRole:
    Description: Implicit IAM Role created for Hello World function
    Value: !GetAtt HelloWorldFunctionRole.Arn
```

## 다음 단계
<a name="monitor-app-insights-next"></a>

 CloudWatch Application Insights를 구성한 후에는 귀하의 애플리케이션을 구축하는데 **sam build**을 사용하고 애플리케이션을 배포하는 데 **sam deploy**을 사용합니다. 모든 CloudWatch Application Insights 지원 리소스는 모니터링을 위해 구성됩니다.
+  지원되는 리소스 목록은 *Amazon CloudWatch 사용자 가이드*에서 [지원되는 로그 및 지표를](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/appinsights-logs-and-metrics.html) 잠조하세요.
+  CloudWatch Application Insights에 액세스하는 방법을 알아보려면 *Amazon CloudWatch 사용자 가이드*의 [CloudWatch Application Insights에 대한 액세스를](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/appinsights-accessing.html) 잠조하세요.