0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[備忘録] AWSでeventのサンプルが欲しいときは

Last updated at Posted at 2024-11-27

概要

AWSでサービスに触れると、eventというワードをよく見かけますが、実際どんな値が入っているのかわからないことがありました。
そんな時、aws-sam-cliを使用することで、eventのサンプルを出力してくれることを知ったのでここに残します。

前提

aws-sam-cliのインストール方法については割愛します。
インストール方法はGitHubまたはAWS公式ページを参照してください。

使用方法

前提コマンド

sam local generate-event {{ AWS サービス }} {{ イベント }}

使用例

$ sam local generate-event s3 put

{
  "Records": [
    {
      "eventVersion": "2.0",
      "eventSource": "aws:s3",
      "awsRegion": "us-east-1",
      "eventTime": "1970-01-01T00:00:00.000Z",
      "eventName": "ObjectCreated:Put",
      "userIdentity": {
        "principalId": "EXAMPLE"
      },
      "requestParameters": {
        "sourceIPAddress": "127.0.0.1"
      },
      "responseElements": {
        "x-amz-request-id": "EXAMPLE123456789",
        "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH"
      },
      "s3": {
        "s3SchemaVersion": "1.0",
        "configurationId": "testConfigRule",
        "bucket": {
          "name": "example-bucket",
          "ownerIdentity": {
            "principalId": "EXAMPLE"
          },
          "arn": "arn:aws:s3:::example-bucket"
        },
        "object": {
          "key": "test/key",
          "size": 1024,
          "eTag": "0123456789abcdef0123456789abcdef",
          "sequencer": "0A1B2C3D4E5F678901"
        }
      }
    }
  ]
}

使用可能なサービス一覧取得

$ sam local generate-event

Commands:
    alexa-skills-kit
    alexa-smart-home
    alb
    apigateway
    appsync
    batch
    cloudformation
    cloudfront
    codecommit
    codepipeline
    cognito
    config
    connect
    dynamodb
    cloudwatch
    kinesis
    lex
    lex-v2
    rekognition
    s3
    sagemaker
    ses
    sns
    sqs
    stepfunctions
    workmail

使用可能なイベント一覧

$ sam local generate-event s3

Commands:
  batch-invocation  Generates an Amazon S3 Batch Operations Invocation Event
  delete            Generates an Amazon S3 Delete Event
  put               Generates an Amazon S3 Put Event
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?