[最終更新] 2022年5月26日
AWSのLambda関数で、S3とかSNSとかのイベントで発火させる時に、event変数に渡されるパラメータのjson形式についてのまとめ。
CloudWatch Events
定期実行のやつ。
{
"version": "0",
"id": "xxxx",
"detail-type": "Scheduled Event",
"source": "aws.events",
"account": "xxxx",
"time": "2021-06-10T06:45:27Z",
"region": "ap-northeast-1",
"resources": [
"arn:aws:events:ap-northeast-1:xxxx:rule/xxxx"
],
"detail": {}
}
S3
最終確認: 2020-10-19
{
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "ap-northeast-1",
"eventTime": "2020-11-11T07:11:11.971Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "AWS:xxxx"
},
"requestParameters": {
"sourceIPAddress": "xxxx"
},
"responseElements": {
"x-amz-request-id": "xxxx",
"x-amz-id-2": "xxxx"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "xxxx",
"bucket": {
"name": "xxxx",
"ownerIdentity": {
"principalId": "xxxx",
},
"arn": "arn:aws:s3:::xxxx"
},
"object": {
"key": "<ファイル名>"
"size": 1110,
"eTag": "b8998f8b6c5bf97ebb47785edcabf58f",
"sequencer": "005FAB8E92A2CE5967"
}
}
}
]
}
DynamoDB Stream
{
'Records': [
{
'eventID': 'xxxxxxxxxxx',
'eventName': 'INSERT' | 'MODIFY' | 'REMOVE',
'eventVersion': '1.1',
'eventSource': 'aws:dynamodb',
'awsRegion': 'ap-northeast-1',
'dynamodb': {
'ApproximateCreationDateTime': 1587462474.0,
'Keys': {'<PK>が入る': {'S': 'hogehoge'}, '<SK>が入る': {'N': '1587462000000'}},
'NewImage' | 'OldImage': {'パラメータ1': {'S': 'fugafuga'}, ...},
'SequenceNumber': 'xxxxxxxxxxxxxxx',
'SizeBytes': 131,
'StreamViewType': 'NEW_IMAGE' | 'NEW_AND_OLD_IMAGES' | 'OLD_IMAGE'
},
'eventSourceARN': 'xxxxxxxxxxx'
},
...
]
}
REMOVEの時は OldImage をいじる。INSERTの時は NewImage。MODIFYは両方。
SNS
最終確認: 2021/10/12
{
"Records": [
{
"EventSource": "aws:sns",
"EventVersion": "1.0",
"EventSubscriptionArn": "xxxx"
"Sns": {
"Type": "Notification",
"MessageId": "xxxx",
"TopicArn": "xxxx"
"Subject": "xxxx",
"Message": "xxxx",
"Timestamp": "2020-11-13T08:56:32.217Z",
"SignatureVersion": "1",
"Signature": "xxxx",
"SigningCertUrl": "xxxx",
"UnsubscribeUrl": "xxxx",
"MessageAttributes": {}
}
}
]
}
AWS IoT -> SNS -> Lambdaの場合
{'WirelessDeviceId': '88d6aace-9702-4f20-9de9-c8d5bfee3533', 'PayloadData': 'AgAAA+gD6APo', 'WirelessMetadata': {'LoRaWAN': {'ADR': False, 'Bandwidth': 125, 'ClassB': False, 'CodeRate': '4/5', 'DataRate': '2', 'DevAddr': 'fe0523c1', 'DevEui': '000b78fffe0523c1', 'FCnt': 16549, 'FOptLen': 0, 'FPort': 1, 'Frequency': '922200000', 'Gateways': [{'GatewayEui': 'b827ebfffeaa9226', 'Rssi': -5, 'Snr': 8}], 'MIC': '24517e52', 'MType': 'UnconfirmedDataUp', 'Major': 'LoRaWANR1', 'Modulation': 'LORA', 'PolarizationInversion': False, 'SpreadingFactor': 10, 'Timestamp': '2021-10-12T10:02:15Z'}}}
S3 -> SNS -> Lambda の場合
SnsレコードのMessageに、S3のRecordがシリアライズドされたjsonで入っている。
CloudWatch -> SNS -> Lambdaの場合
SnsレコードのMessageに、以下のシリアライドされたjsonが入っている。
{
'AlarmName': 'xxxx',
'AlarmDescription': None,
'AWSAccountId': 'xxxx',
'NewStateValue': 'ALARM',
'NewStateReason': 'xxxx',
'StateChangeTime': '2020-10-12T04:50:22.996+0000',
'Region': 'Asia Pacific Tokyo',
'AlarmArn': 'xxxx',
'OldStateValue': 'OK',
'Trigger': {
'MetricName': '4XXError',
'Namespace': 'AWS/ApiGateway',
'StatisticType': 'Statistic',
'Statistic': 'AVERAGE',
'Unit': None,
'Dimensions':
[
{
'value': 'xxxx',
'name': 'xxxx'
}
],
'Period': 300,
'EvaluationPeriods': 1,
'ComparisonOperator': 'GreaterThanThreshold',
'Threshold': 0.03,
'TreatMissingData': 'xxxx'
'EvaluateLowSampleCountPercentile': ''
}
}
関連記事
aws の記事
- [2021年6月12日] DynamoDBの多対多で隣接リストやった時の冗長性対策どうしよう
- [2021年5月13日] Lambda関数でDeadLetterQueue(DLQ)を試す
- [2021年1月25日] AWS Lambdaのロギングを考える
- [2021年1月12日] AWS Lambdaをデプロイした時のダウンタイム
- [2020年12月8日] DynamoDB から DocumentClient で get() した StringSet型 の値を取り出す
- ---本記事---
- [2020年10月13日] AWS Lambda (Python 3.8)から Amazon Elasticsearchを使う(LambdaはSAMで)
- [2020年10月12日] AWS SAM CLIでSNSからLambdaを起動する(Python 3.8)、S3からSNSに通知する
- [2020年5月13日] Grafana on EC2 で Let’s Encrypt 使ってSSL
- [2020年4月28日] httpでPOSTする受け口をSAM CLI + API Gateway + Lambdaで作る
- [2020年4月26日] DynamoDBで多対多のテーブル設計
スポンサーリンク