Skip to content

Instantly share code, notes, and snippets.

@yasudacloud
Created March 12, 2024 14:32
Show Gist options
  • Save yasudacloud/de6924c9f51576f73e5cedd49ffc799a to your computer and use it in GitHub Desktop.
Save yasudacloud/de6924c9f51576f73e5cedd49ffc799a to your computer and use it in GitHub Desktop.
ec2 describe script
#!/bin/bash
set -e
# AWS CLIを使用してEC2インスタンス情報を取得
aws_output=$(aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value | [0]]' --output json)
# TypeScriptファイルへの変換
typescript_code=$(echo "$aws_output" | jq -r '. | map({"name": .[0][1], "value": .[0][0]}) | .')
echo "export const instances = $typescript_code;" > functions/resources.ts
cat functions/resources.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment