0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Lambda関数内でCloudWatch LogsのログストリームURLを取得する

Posted at

Lambda関数内でCloudWatch LogsのログストリームURLを取得する

AWS Lambda関数内でAWS CloudWatch LogsのログストリームURLを取得する方法に関する記事はいくつか見つかりますが、ここではエンコードせずに最もシンプルに書く方法を紹介します。

使用言語はPythonです。

必要な情報をコンテクストから取得する

handler.py
import os

def lambda_handler(event, context):
    region = os.getenv('AWS_REGION') or os.getenv('AWS_DEFAULT_REGION')
    log_group = context.log_group_name
    log_stream = context.log_stream_name

ログストリームURLを生成する

handler.py
def lambda_handler(event, context):
    # 省略
    url = f'https://console.aws.amazon.com/cloudwatch/home?region={region}'\
          f'#logEventViewer:group={log_group};stream={log_stream}'

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?