JAWS-UG CLI #25 LT
AWS Tools for Windows PowerShellで
ログを出力
2015/08/03 Mon
Nobuhiro Nakayama
2
cat << EOF > me.json
{
“name” : “Nobuhiro Nakayama”,
“company” : “UCHIDAYOKO CO., LTD.”,
“favorite aws services” : [
“Directory Service”, “IAM”, “CLI”
],
“twitter” : ”@domokun70cm”,
“facebook” : ” nobuhiro.nakayama.12”,
“certifications” : [
“AWS Certified Solutions Architect-Professional”,
“AWS Certified SysOps Administrator-Associate”,
“Microsoft Certified Solutions Expert Server Infrastructure / SharePoint”,
“IPA Network Specialist”, “IPA Information Security Specialist”
]
}
EOF
Agenda
• AWS Tools for PowerShellとは
• Metrics Logging/Logging Listener
2015/8/3 3
AWS Tools for Windows PowerShell
• PowerShellでAWSを操作するツール
• コマンドレットの出力結果は.NET Frameworkオブジェクトの配列として出力
• 細かいことは、先々週のBlackBelt Tech Webinarの資料で
• http://www.slideshare.net/AmazonWebServicesJapan/aws-black-belt-tech-2015-
aws-cloudtrail-aws-sdk-for-powershell
2015/8/3 4
今日紹介する機能は、Blackbelt Tech Webinarで
紹介されていないちょっと便利な機能です
Metrics Logging/Logging Listener
• 実行結果のログを取得できます(Get-EC2AvailabilityZoneの例)
• 実行結果の他、実行に要した時間なども出力される(Linuxのtimeコマンドのようなもの)
2015/8/3 5
Amazon Verbose: 0 : Received response (truncated to 1024 bytes): [<?xml version="1.0" encoding="UTF-
8"?><DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2015-04-15/"> <requestId>577e1785-a53a-42fa-
8119-2f7d9100376d</requestId> <availabilityZoneInfo> <item> <zoneName>ap-northeast-1a</zoneName>
<zoneState>available</zoneState> <regionName>ap-northeast-1</regionName> <messageSet/> </item>
<item> <zoneName>ap-northeast-1c</zoneName> <zoneState>available</zoneState> <regionName>ap-
northeast-1</regionName> <messageSet/> </item> </availabilityZoneInfo></DescribeAvailabilityZonesResponse>]
Amazon Information: 1 : Request metrics: AsyncCall = False; CanonicalRequest = POST¥n/¥n¥ncontent-type:application/x-www-form-
urlencoded; charset=utf-8¥nhost:ec2.ap-northeast-1.amazonaws.com¥nuser-agent:AWSPowerShell/2.3.46.0 .NET Runtime/4.0 .NET
Framework/4.0 OS/6.1.7601.65536 WindowsPowerShell/4.-1 ClientSync¥nx-amz-content-
sha256:a4541cc6cd06d90dbf380a65d6eaab5b64476077df590c1b7d34985c7100f489¥nx-amz-date:20150802T113641Z¥n¥ncontent-
type;host;user-agent;x-amz-content-sha256;x-amz-date¥na4541cc6cd06d90dbf380a65d6eaab5b64476077df590c1b7d34985c7100f489;
StringToSign = AWS4-HMAC-SHA256¥n20150802T113641Z¥n20150802/ap-northeast-
1/ec2/aws4_request¥n32b22900d41c9cc4d2cef2d35cc6b1ef67966f8d0a50ed6ecc887c43b23ca720; ServiceName = Amazon.EC2;
ServiceEndpoint = https://ec2.ap-northeast-1.amazonaws.com/; MethodName = DescribeAvailabilityZonesRequest; RequestSize = 51;
StatusCode = OK; BytesProcessed = -1; AWSRequestID = 577e1785-a53a-42fa-8119-2f7d9100376d; CredentialsRequestTime =
00:00:00.0000027; RequestSigningTime = 00:00:00.0008425; HttpRequestTime = 00:00:00.0990260; ResponseUnmarshallTime =
00:00:00.0002682; ResponseProcessingTime = 00:00:00.0022254; ClientExecuteTime = 00:00:00.1327580;
【参考】Get-EC2AvailabilityZoneの実行結果
• DefaultRegionがap-northeast-1の場合
2015/8/3 6
Messages RegionName State ZoneName
-------- ---------- ----- --------
{} ap-northeast-1 available ap-northeast-1a
{} ap-northeast-1 available ap-northeast-1c
Metrics Logging/Logging Listener
• 設定方法
1. リスナーを定義
2. ログの取得レベルの設定
3. ログ取得の有効化
2015/8/3 7
1.リスナーを定義
• リスナー名とログファイルの出力先を指定
• ソース(サービス)を指定してログファイルを分けることも可能
• “-Source”なし・ありのリスナーを複数設定した場合、
-Sourceを指定していないリスナーでは
-Sourceを指定したリスナーのログは出力されませんでした。
• 同じ-Sourceを指定した複数のリスナーを設定している場合、両方に出力されました。
2015/8/3 8
> Add-AWSLoggingListener –Name AllLogs -LogFilePath c:¥logs¥all.txt
> Add-AWSLoggingListener –Name S3Logs -LogFilePath c:¥logs¥s3.txt –Source Amazon.S3
2.ログの取得レベルの設定
• 出力するログの種類を指定
• Alwaysの他に、Never及びOnErrorを設定可能
• リスナー毎に設定することはできない
2015/8/3 9
> Set-AWSResponseLogging -Level always
3.ログ取得の有効化
• ログの出力を有効化
2015/8/3 10
> Enable-AWSMetricsLogging
【参考】log4net
• log4netが使われているもよう
2015/8/3 11
> Get-AWSPowerShellVersion
AWS Tools for Windows PowerShell
Version 3.1.2.0
Copyright 2012-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Amazon Web Services SDK for .NET
Version 3.1.0.0
Copyright 2009-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Release notes: https://aws.amazon.com/releasenotes/PowerShell
This software includes third party software subject to the following copyrights:
- Logging from log4net, Apache License
[http://logging.apache.org/log4net/license.html]
注意事項
• ウィンドウを閉じると設定は無効化される
• 再設定が必要
• ログの出力先に同じファイルを指定した場合、追記される
• 他に何かあれば教えてくださいw
2015/8/3 12
まとめ
• ログの取得を丸投げできて便利
• Set-AWSResponseLogging –Levelをリスナー毎に設定できたら便利かも
• CLIにも似たような機能があればいいなー
2015/8/3 13

JAWS-UG CLI #25 LT - AWS Tools for Windows PowerShellでログを取得

  • 1.
    JAWS-UG CLI #25LT AWS Tools for Windows PowerShellで ログを出力 2015/08/03 Mon Nobuhiro Nakayama
  • 2.
    2 cat << EOF> me.json { “name” : “Nobuhiro Nakayama”, “company” : “UCHIDAYOKO CO., LTD.”, “favorite aws services” : [ “Directory Service”, “IAM”, “CLI” ], “twitter” : ”@domokun70cm”, “facebook” : ” nobuhiro.nakayama.12”, “certifications” : [ “AWS Certified Solutions Architect-Professional”, “AWS Certified SysOps Administrator-Associate”, “Microsoft Certified Solutions Expert Server Infrastructure / SharePoint”, “IPA Network Specialist”, “IPA Information Security Specialist” ] } EOF
  • 3.
    Agenda • AWS Toolsfor PowerShellとは • Metrics Logging/Logging Listener 2015/8/3 3
  • 4.
    AWS Tools forWindows PowerShell • PowerShellでAWSを操作するツール • コマンドレットの出力結果は.NET Frameworkオブジェクトの配列として出力 • 細かいことは、先々週のBlackBelt Tech Webinarの資料で • http://www.slideshare.net/AmazonWebServicesJapan/aws-black-belt-tech-2015- aws-cloudtrail-aws-sdk-for-powershell 2015/8/3 4 今日紹介する機能は、Blackbelt Tech Webinarで 紹介されていないちょっと便利な機能です
  • 5.
    Metrics Logging/Logging Listener •実行結果のログを取得できます(Get-EC2AvailabilityZoneの例) • 実行結果の他、実行に要した時間なども出力される(Linuxのtimeコマンドのようなもの) 2015/8/3 5 Amazon Verbose: 0 : Received response (truncated to 1024 bytes): [<?xml version="1.0" encoding="UTF- 8"?><DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2015-04-15/"> <requestId>577e1785-a53a-42fa- 8119-2f7d9100376d</requestId> <availabilityZoneInfo> <item> <zoneName>ap-northeast-1a</zoneName> <zoneState>available</zoneState> <regionName>ap-northeast-1</regionName> <messageSet/> </item> <item> <zoneName>ap-northeast-1c</zoneName> <zoneState>available</zoneState> <regionName>ap- northeast-1</regionName> <messageSet/> </item> </availabilityZoneInfo></DescribeAvailabilityZonesResponse>] Amazon Information: 1 : Request metrics: AsyncCall = False; CanonicalRequest = POST¥n/¥n¥ncontent-type:application/x-www-form- urlencoded; charset=utf-8¥nhost:ec2.ap-northeast-1.amazonaws.com¥nuser-agent:AWSPowerShell/2.3.46.0 .NET Runtime/4.0 .NET Framework/4.0 OS/6.1.7601.65536 WindowsPowerShell/4.-1 ClientSync¥nx-amz-content- sha256:a4541cc6cd06d90dbf380a65d6eaab5b64476077df590c1b7d34985c7100f489¥nx-amz-date:20150802T113641Z¥n¥ncontent- type;host;user-agent;x-amz-content-sha256;x-amz-date¥na4541cc6cd06d90dbf380a65d6eaab5b64476077df590c1b7d34985c7100f489; StringToSign = AWS4-HMAC-SHA256¥n20150802T113641Z¥n20150802/ap-northeast- 1/ec2/aws4_request¥n32b22900d41c9cc4d2cef2d35cc6b1ef67966f8d0a50ed6ecc887c43b23ca720; ServiceName = Amazon.EC2; ServiceEndpoint = https://ec2.ap-northeast-1.amazonaws.com/; MethodName = DescribeAvailabilityZonesRequest; RequestSize = 51; StatusCode = OK; BytesProcessed = -1; AWSRequestID = 577e1785-a53a-42fa-8119-2f7d9100376d; CredentialsRequestTime = 00:00:00.0000027; RequestSigningTime = 00:00:00.0008425; HttpRequestTime = 00:00:00.0990260; ResponseUnmarshallTime = 00:00:00.0002682; ResponseProcessingTime = 00:00:00.0022254; ClientExecuteTime = 00:00:00.1327580;
  • 6.
    【参考】Get-EC2AvailabilityZoneの実行結果 • DefaultRegionがap-northeast-1の場合 2015/8/3 6 MessagesRegionName State ZoneName -------- ---------- ----- -------- {} ap-northeast-1 available ap-northeast-1a {} ap-northeast-1 available ap-northeast-1c
  • 7.
    Metrics Logging/Logging Listener •設定方法 1. リスナーを定義 2. ログの取得レベルの設定 3. ログ取得の有効化 2015/8/3 7
  • 8.
    1.リスナーを定義 • リスナー名とログファイルの出力先を指定 • ソース(サービス)を指定してログファイルを分けることも可能 •“-Source”なし・ありのリスナーを複数設定した場合、 -Sourceを指定していないリスナーでは -Sourceを指定したリスナーのログは出力されませんでした。 • 同じ-Sourceを指定した複数のリスナーを設定している場合、両方に出力されました。 2015/8/3 8 > Add-AWSLoggingListener –Name AllLogs -LogFilePath c:¥logs¥all.txt > Add-AWSLoggingListener –Name S3Logs -LogFilePath c:¥logs¥s3.txt –Source Amazon.S3
  • 9.
    2.ログの取得レベルの設定 • 出力するログの種類を指定 • Alwaysの他に、Never及びOnErrorを設定可能 •リスナー毎に設定することはできない 2015/8/3 9 > Set-AWSResponseLogging -Level always
  • 10.
  • 11.
    【参考】log4net • log4netが使われているもよう 2015/8/3 11 >Get-AWSPowerShellVersion AWS Tools for Windows PowerShell Version 3.1.2.0 Copyright 2012-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. Amazon Web Services SDK for .NET Version 3.1.0.0 Copyright 2009-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. Release notes: https://aws.amazon.com/releasenotes/PowerShell This software includes third party software subject to the following copyrights: - Logging from log4net, Apache License [http://logging.apache.org/log4net/license.html]
  • 12.
    注意事項 • ウィンドウを閉じると設定は無効化される • 再設定が必要 •ログの出力先に同じファイルを指定した場合、追記される • 他に何かあれば教えてくださいw 2015/8/3 12
  • 13.
    まとめ • ログの取得を丸投げできて便利 • Set-AWSResponseLogging–Levelをリスナー毎に設定できたら便利かも • CLIにも似たような機能があればいいなー 2015/8/3 13