CloudWatch Application Insights を使用してサーバーレスアプリケーションをモニタリングする - AWS Serverless Application Model

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

CloudWatch Application Insights を使用してサーバーレスアプリケーションをモニタリングする

Amazon CloudWatch Application Insights は、アプリケーション内の AWS リソースをモニタリングして潜在的な問題を特定するのに役立ちます。 AWS リソースデータを分析して問題の兆候がないか確認し、自動ダッシュボードを構築して可視化できます。 AWS Serverless Application Model (AWS SAM) アプリケーションで使用するように CloudWatch Application Insights を設定できます。 CloudWatch Application Insights の詳細については、「Amazon ユーザーガイド」の「Amazon CloudWatch Application Insights」を参照してください。 CloudWatch

を使用した CloudWatch Application Insights の設定 AWS SAM

AWS SAM コマンドラインインターフェイス (AWS SAMCLI) または AWS SAM テンプレートを使用して AWS SAM 、アプリケーションの CloudWatch Application Insights を設定します。

AWS SAM CLI による設定

でアプリケーションを初期化するときは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」を参照してください。

AWS SAM テンプレートを使用して を設定する

AWS SAM テンプレートで AWS::ResourceGroups::Groupおよび CloudWatch AWS::ApplicationInsights::Applicationリソースを定義して 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 ユーザーガイド」の「AWS::ResourceGroups::Group」を参照してください。

  • AWS::ApplicationInsights::Application – リソースグループの CloudWatch Application Insights を設定します。このリソースタイプの詳細については、「AWS CloudFormation ユーザーガイド」の「AWS::ApplicationInsights::Application」を参照してください。

両方のリソースは、アプリケーションのデプロイ AWS CloudFormation 時に に自動的に渡されます。 AWS SAM テンプレート AWS CloudFormation の構文を使用して、Application Insights CloudWatch をさらに設定できます。詳細については、「Amazon ユーザーガイド」の AWS CloudFormation 「 テンプレートの使用」を参照してください。 CloudWatch

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

次のステップ

CloudWatch Application Insights を設定したら、 sam buildを使用してアプリケーションを構築し、 sam deploy を使用してアプリケーションをデプロイします。 CloudWatch Application Insights がサポートするすべてのリソースは、モニタリング用に設定されます。