AWS CLIで月160万円の負債を 解消した話 / AWS CLI debt resolution

Cd34440e6c181704f318319e131af68d?s=47 OouchiNaoki
September 20, 2020

AWS CLIで月160万円の負債を 解消した話 / AWS CLI debt resolution

AWS CLIで月160万円の負債を 解消した話 / AWS CLI debt resolution
https://www.ooooouchi.info/

Cd34440e6c181704f318319e131af68d?s=128

OouchiNaoki

September 20, 2020
Tweet

Transcript

  1. AWS CLIͰ݄160ສԁͷෛ࠴Λ ղফͨ͠࿩ େ಺ ௚थʢ@NaoNoaNaoNoaNʣ 2020.09.24

  2. େ಺ ௚थ @NaoNoaNaoNoaN • System Shared, Inc. • AWS, Nuxt.js,

    Node.js, TypeScript • ٳ೔͸Α͘ເͷࠃʹߦ·͢ • ϒϩάॻ͍ͯ·͢ https://www.ooooouchi.info/
  3. ຊ୊ͷલʹ

  4. System Shared, Inc. Ͳ͏͍͏ձࣾʁ

  5. SES΍ͬͯ·͢

  6. डୗ։ൃ΍ͬͯ·͢

  7. ৽ଔ޲͚ITݚम΍ͬͯ·͢ ʢ̐ʙ݄̒ʣ

  8. ݚमதʹ AWSͷೖ໳΋΍ͬͯ·͢ ʢ̏೔͘Β͍ʣ

  9. ࣗࣾαʔϏε΋΍ͬͯ·͢

  10. AWSΞΧ΢ϯτ؅ཧ୅ߦαʔϏε ʢڴҖݕ஌ͱ͔༧ࢉ؅ཧͱ͔΍ͬͯ·͢ʣ

  11. None
  12. ͜Ε͸ System Shared, Inc.͕ ݚमੜͷAWSΞΧ΢ϯτΛ ؅ཧ୅ߦͨ࣌͠ͷ ෺ޠ

  13. ຊ୊

  14. AWSೖ໳ݚमͰ࢖͏ AWSϦιʔε

  15. EIP + EC2 + RDS

  16. ݚमੜͷAWSΞΧ΢ϯτ͸ AWS OrganizationsͰ૊৫؅ཧͯ͠Δ →ແྉར༻࿮࢒ྔͳ͠

  17. Ϧιʔείετ ֹ݄໿2000ԁ

  18. ݚमੜͷ਺

  19. 800ਓऑ

  20. 2000 × 800 = ʁ

  21. 1,600,000

  22. ̏೔͘Β͍ͷݚमͰ ݄160ສԁͷෛ࠴

  23. ղܾ͍͖ͯ͠·͢

  24. ղܾํ๏

  25. StepFunctions + Lambda Node.js + AWS SDK Ͱ֤छϦιʔεΛফ͢

  26. ςετ༻ʹ༻ҙͨ͠ AWSΞΧ΢ϯτ 10ΞΧ΢ϯτͰ࡟আ੒ޭ

  27. ͍͟ຊ൪

  28. Τϥʔൃੜ

  29. The state/task ‘arn:xxxxxxxxxxxxxxxx’ returned a result with a size exceeding

    the maximum number of characters service limit.
  30. λεΫؒͷύϥϝʔλαΠζ͕େ͖͗͢Δ ※্ݶɿ32,768byte

  31. 800ΞΧ΢ϯτ෼ͷ৘ใΛ౉͢ʹ͸ গͳ͗͢Δ

  32. ࠔͬͨɾɾ

  33. ͓ʁ

  34. None
  35. ͜Εͩʂʂ

  36. Shell + AWS CLI

  37. AWSΞΧ΢ϯτIDΛऔಘͯ͠ aws organizations list-accounts-for-parent \ --parent-id ${OU_ID} \ --profile ${AWS_PROFILE_NAME}

    | jq -r ".Accounts[].Id" | sed -e "s/[\r\n]\+//g"
  38. શϦʔδϣϯ໊Λऔಘͯ͠ regions=$( aws ec2 describe-regions \ --query Regions[*].RegionName \ --output

    text \ --region ap-northeast-1 )
  39. EC2Πϯελϯε࡟আ INSTANCE_IDS=$( aws ec2 describe-instances \ --region $1 \ --filters

    “Name=instance-state-name, Values=pending,running,stopped,stopping" \ --query "Reservations[].Instances[].[InstanceId]" \ --output text | sed -e "s/[\r\n]\+//g" ) if [ -n "${INSTANCE_IDS[0]}" ]; then aws ec2 terminate-instances \ --instance-ids ${INSTANCE_IDS} \ --region $1 fi
  40. EBS,NAT,EIP,RDS ҎԼಉจ

  41. AWS CLIͰ݄160ສԁͷෛ࠴Λղফ ׬ྃ

  42. ·ͱΊ

  43. Կࣄ΋εέʔϧͱϦϛοτΛ֬ೝ͠Α͏

  44. ݄160ສͷϚΠφεΛ0ʹͨ͠ ͱ͍͏͜ͱ͸ɾɾʁ

  45. AWS CLIΛ࢖͏ͱ ݄160ສԁউͯΔ ʢΪϟϯϒϥʔࢥߟʣ

  46. Φν

  47. ύϥϝʔλαΠζͷ্ݶ؇࿨͞Εͯͨ

  48. ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ