Last active
April 28, 2021 06:22
-
-
Save arc279/26fa26bb18b7da1ae5965792a53deccc to your computer and use it in GitHub Desktop.
ネストしたjsonをjq で辿る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.. # 再帰的に辿る | |
| objects # object のみに絞る | |
| to_entries[] # key, value を分離 | |
| select(.value.Type? == "Task") # 'Type' キーが存在する && その値が "Task" ものだけ抽出 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# サンプルはこちらにある json | |
# https://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/sample-map-state.html | |
run: | |
@ cat sample.asl.json | jq -f a.jq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"key": "Read messages from SQS Queue", | |
"value": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::lambda:invoke", | |
"OutputPath": "$.Payload", | |
"Parameters": { | |
"FunctionName": "MapSampleProj-ReadFromSQSQueueLambda-1MY3M63RMJVA9" | |
}, | |
"Next": "Are there messages to process?" | |
} | |
} | |
{ | |
"key": "Write message to DynamoDB", | |
"value": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::dynamodb:putItem", | |
"ResultPath": null, | |
"Parameters": { | |
"TableName": "MapSampleProj-DDBTable-YJDJ1MKIN6C5", | |
"ReturnConsumedCapacity": "TOTAL", | |
"Item": { | |
"MessageId": { | |
"S.$": "$.MessageDetails.MessageId" | |
}, | |
"Body": { | |
"S.$": "$.MessageDetails.Body" | |
} | |
} | |
}, | |
"Next": "Remove message from SQS queue" | |
} | |
} | |
{ | |
"key": "Remove message from SQS queue", | |
"value": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::lambda:invoke", | |
"InputPath": "$.MessageDetails", | |
"ResultPath": null, | |
"Parameters": { | |
"FunctionName": "MapSampleProj-DeleteFromSQSQueueLambda-198J2839ZO5K2", | |
"Payload": { | |
"ReceiptHandle.$": "$.ReceiptHandle" | |
} | |
}, | |
"Next": "Publish message to SNS topic" | |
} | |
} | |
{ | |
"key": "Publish message to SNS topic", | |
"value": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::sns:publish", | |
"InputPath": "$.MessageDetails", | |
"Parameters": { | |
"Subject": "Message from Step Functions!", | |
"Message.$": "$.Body", | |
"TopicArn": "arn:aws:sns:us-east-1:012345678910:MapSampleProj-SNSTopic-1CQO4HQ3IR1KN" | |
}, | |
"End": true | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Comment": "An example of the Amazon States Language for reading messages from an SQS queue and iteratively processing each message.", | |
"StartAt": "Read messages from SQS Queue", | |
"States": { | |
"Read messages from SQS Queue": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::lambda:invoke", | |
"OutputPath": "$.Payload", | |
"Parameters": { | |
"FunctionName": "MapSampleProj-ReadFromSQSQueueLambda-1MY3M63RMJVA9" | |
}, | |
"Next": "Are there messages to process?" | |
}, | |
"Are there messages to process?": { | |
"Type": "Choice", | |
"Choices": [ | |
{ | |
"Variable": "$", | |
"StringEquals": "No messages", | |
"Next": "Finish" | |
} | |
], | |
"Default": "Process messages" | |
}, | |
"Process messages": { | |
"Type": "Map", | |
"Next": "Finish", | |
"ItemsPath": "$", | |
"Parameters": { | |
"MessageNumber.$": "$$.Map.Item.Index", | |
"MessageDetails.$": "$$.Map.Item.Value" | |
}, | |
"Iterator": { | |
"StartAt": "Write message to DynamoDB", | |
"States": { | |
"Write message to DynamoDB": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::dynamodb:putItem", | |
"ResultPath": null, | |
"Parameters": { | |
"TableName": "MapSampleProj-DDBTable-YJDJ1MKIN6C5", | |
"ReturnConsumedCapacity": "TOTAL", | |
"Item": { | |
"MessageId": { | |
"S.$": "$.MessageDetails.MessageId" | |
}, | |
"Body": { | |
"S.$": "$.MessageDetails.Body" | |
} | |
} | |
}, | |
"Next": "Remove message from SQS queue" | |
}, | |
"Remove message from SQS queue": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::lambda:invoke", | |
"InputPath": "$.MessageDetails", | |
"ResultPath": null, | |
"Parameters": { | |
"FunctionName": "MapSampleProj-DeleteFromSQSQueueLambda-198J2839ZO5K2", | |
"Payload": { | |
"ReceiptHandle.$": "$.ReceiptHandle" | |
} | |
}, | |
"Next": "Publish message to SNS topic" | |
}, | |
"Publish message to SNS topic": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::sns:publish", | |
"InputPath": "$.MessageDetails", | |
"Parameters": { | |
"Subject": "Message from Step Functions!", | |
"Message.$": "$.Body", | |
"TopicArn": "arn:aws:sns:us-east-1:012345678910:MapSampleProj-SNSTopic-1CQO4HQ3IR1KN" | |
}, | |
"End": true | |
} | |
} | |
} | |
}, | |
"Finish": { | |
"Type": "Succeed" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment