Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dockerを使ってS3ローカル開発環境を構築した

 Dockerを使ってS3ローカル開発環境を構築した

2022/2/16(水)に行われた【JAWS-UG 初心者支部#45 AWS Builders Online Series recap3】にて発表した
「Dockerを使ってS3ローカル開発環境を構築した」
の資料です。

Takafumi Omuro

February 16, 2022
Tweet

More Decks by Takafumi Omuro

Other Decks in Technology

Transcript

  1. %PDLFSΛ࢖ͬͯ 4ϩʔΧϧ։ൃ؀ڥΛߏஙͨ͠ גࣜձࣾϞϦαϫ খࣨو࢙

  2. ໊લɿখࣨو࢙ ࣗݾ঺հ ࢓ࣄɿςοΫϦʔυ ɹɹɹ"84ΠϯϑϥΤϯδχΞ ޷͖ͳαʔϏεɿ$MPVE'PSNBUJPO ॴଐɿגࣜձࣾϞϦαϫ ɹɹɹγεςϜ։ൃ෦ ɹɹɹΠϊϕʔγϣϯ։ൃ՝ɹ

  3. w -PDBM4UBDLͱ͸ w %PDLFSͰࢼ͢ w 4΁ΞΫηε w ·ͱΊ ΞδΣϯμ

  4. "84ͷϩʔΧϧ։ൃ͍ͨ͠

  5. -PDBM4UBDLͱ͍͏ͷ͕ ͋ΔΒ͍͠

  6. -PDBM4UBDLͱ͸ "84ϞοΫϑϨʔϜϫʔΫ w ϩʔΧϧʹ"84ͷϞοΫ؀ڥΛ࡞Δ͜ͱ͕Ͱ͖Δ w "84αʔϏεͷΤϛϡϨʔλʔ w QJQͱ%PDLFSΠϝʔδͰఏڙ͞Ε͍ͯΔ w QZUIPO

    1ZUIPOVQUPTVQQPSUFE  w QJQ 1ZUIPOQBDLBHFNBOBHFS  w %PDLFS w ެࣜαΠτɿIUUQTMPDBMTUBDLDMPVE w 044ɿIUUQTHJUIVCDPNMPDBMTUBDLMPDBMTUBDL
  7. -PDBM4UBDLରԠαʔϏε $PNNVOJUZ&EJUJPOʢແྉʣ w "$. w "1*(BUFXBZ w $MPVE'PSNBUJPO w $MPVE8BUDI

    w $MPVE8BUDI-PHT w %ZOBNP%# w %ZOBNP%#4USFBNT w &$ w &MBTUJDTFBSDI4FSWJDF w &WFOU#SJEHF $MPVE8BUDI&WFOUT  w 'JSFIPTF w *". w ,JOFTJT w ,.4 w -BNCEB w 3FETIJGU w 3PVUF w 4 w 4FDSFUT.BOBHFS w 4&4 w 4/4 w 424 w 44. w 4UFQ'VODUJPOT w 454
  8. -PDBM4UBDLରԠαʔϏε 1SP&EJUJPOʢ༗ྉʣ w "NQMJGZ w "1*(BUFXBZ7 8FC4PDLFUTTVQQPSU  w "1*(BUFXBZ7

    w "QQ$POpH w "QQMJDBUJPO"VUP4DBMJOH w "QQ4ZOD w "UIFOB w #BDLVQ w #BUDI w $MPVE'SPOU w $MPVE5SBJM w $PEF$PNNJU w $PHOJUP*EFOUJUZ w $PHOJUP*EFOUJUZ1SPWJEFS *E1  w %PDVNFOU%# w &$ BEWBODFEGFBUVSFT MBVODIJOH7.T  w &$3 w &$4 w &,4 w &MBTUJ$BDIF w &.3 w (MBDJFS44FMFDU w (MVF w *". TFDVSJUZQPMJDZFOGPSDFNFOU  w *P5 JODMVEJOH*P5"OBMZUJDT *P5%BUB  w ,JOFTJT w ,JOFTJT%BUB"OBMZUJDT w -BNCEB JODMVEJOH-BNCEB-BZFST$POUBJOFS*NBHFT  w .BOBHFE4USFBNJOHGPS,BGLB .4,  w .FEJB4UPSF w /FQUVOF%# w 2-%# w 3%4"VSPSB4FSWFSMFTT w 3FETIJGU 1PTUHSFT%#TVQQPSU  w 3PVUF %/4JOUFHSBUJPO  w 4BHF.BLFS w 5JNFTUSFBN w 5SBOTGFS w 93BZ IUUQTMPDBMTUBDLDMPVEGFBUVSFTΑΓ
  9. %PDLFSͰࢼͯ͠Έͨ

  10. %PDLFSͰࢼ͢ %PDLFSͷ४උ w %PDLFS%FTLUPQͷ४උ w ݸਓར༻͸ແྉ w ۀ຿Ͱ࢖͏ͱ͖͸اۀن໛ʹΑΓ༗ྉͳͷͰ֬ೝ͕ඞཁ w %PDLFSpMFΛ࡞੒͢Δ͔%PDLFS)VCͷΠϝʔδΛ࢖͏

    w %PDLFSpMF w IUUQTHJUIVCDPNMPDBMTUBDLMPDBMTUBDLCMPCNBTUFS%PDLFSpMF w %PDLFS)VC w MPDBMTUBDLMPDBMTUBDL w IUUQTIVCEPDLFSDPNSMPDBMTUBDLMPDBMTUBDL
  11. %PDLFSͰࢼ͢ %PDLFSͷ४උ w %PDLFS%FTLUPQͷ४උ w ݸਓར༻͸ແྉ w ۀ຿Ͱ࢖͏ͱ͖͸اۀن໛ʹΑΓ༗ྉͳͷͰ֬ೝ͕ඞཁ w %PDLFSpMFΛ࡞੒͢Δ͔%PDLFS)VCͷΠϝʔδΛ࢖͏

    w %PDLFSpMF w IUUQTHJUIVCDPNMPDBMTUBDLMPDBMTUBDLCMPCNBTUFS%PDLFSpMF w %PDLFS)VC w MPDBMTUBDLMPDBMTUBDL w IUUQTIVCEPDLFSDPNSMPDBMTUBDLMPDBMTUBDL
  12. %PDLFSͰࢼ͢ %PDLFS$PNQPTFͷ४උ version: "3" services: localstack: image: localstack/localstack:0.13.3 container_name: localstack

    ports: - 4566:4566 environment: - DEFAULT_REGION=ap-northeast-1 - SERVICES=s3 - DATA_DIR=/tmp/localstack/data volumes: - localstack:/tmp/localstack/ volumes: localstack:
  13. %PDLFSͰࢼ͢ %PDLFS$PNQPTFͷ४උ version: "3" services: localstack: image: localstack/localstack:0.13.3 container_name: localstack

    ports: - 4566:4566 environment: - DEFAULT_REGION=ap-northeast-1 - SERVICES=s3 - DATA_DIR=/tmp/localstack/data volumes: - localstack:/tmp/localstack/ volumes: localstack: λά৘ใΛ֬ೝͯ͠ ࠷৽Λࢦఆ
  14. %PDLFSͰࢼ͢ %PDLFS$PNQPTFͷ४උ version: "3" services: localstack: image: localstack/localstack:0.13.3 container_name: localstack

    ports: - 4566:4566 environment: - DEFAULT_REGION=ap-northeast-1 - SERVICES=s3 - DATA_DIR=/tmp/localstack/data volumes: - localstack:/tmp/localstack/ volumes: localstack: -PDBM4UBDL͕αʔϏεͰ ར༻͢Δϙʔτ
  15. %PDLFSͰࢼ͢ %PDLFS$PNQPTFͷ४උ version: "3" services: localstack: image: localstack/localstack:0.13.3 container_name: localstack

    ports: - 4566:4566 environment: - DEFAULT_REGION=ap-northeast-1 - SERVICES=s3 - DATA_DIR=/tmp/localstack/data volumes: - localstack:/tmp/localstack/ volumes: localstack: 4Λ౦ژϦʔδϣϯ ͱͯ͠ࢼ͢
  16. %PDLFSͰࢼ͢ %PDLFS$PNQPTFͷ४උ version: "3" services: localstack: image: localstack/localstack:0.13.3 container_name: localstack

    ports: - 4566:4566 environment: - DEFAULT_REGION=ap-northeast-1 - SERVICES=s3 - DATA_DIR=/tmp/localstack/data volumes: - localstack:/tmp/localstack/ volumes: localstack: %PDLFS࠶ىಈ࣌ʹ 4ͷσʔλ͕ ফ͑ͳ͍Α͏ʹ ӬଓԽ͓ͯ͘͠
  17. %PDLFSͰࢼ͢ %PDLFSΛىಈ $ docker-compose up -d Creating network "localstack_default" with

    the default driver Creating volume "localstack_localstack" with default driver Creating localstack ... done $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4c337f07f604 localstack/localstack:0.13.3 "docker- entrypoint.sh" About a minute ago Up About a minute 4571/tcp, 0.0.0.0:4566->4566/tcp, 5678/tcp localstack ϙʔτΛ ϗετଆʹެ։
  18. 4ʹΞΫηεͯ͠ΈΔ

  19. 4ʹΞΫηε "84μϛʔϓϩϑΝΠϧ࡞੒ $ cat >> ~/.aws/credentials << EOF [LocalStack] aws_access_key_id

    = dummy aws_secret_access_key = dummy EOF $ cat >> ~/.aws/config << EOF [profile LocalStack] region = ap-northeast-1 output = json EOF w "84$-*ͰΞΫηε͢ΔͨΊϓϩϑΝΠϧ͕ඞཁ w μϛʔͷϓϩϑΝΠϧΛ࡞੒͓ͯ͘͠
  20. 4ʹΞΫηε 4ίϚϯυΛࢼ͢ w BXTT΍BXTTBQJͷར༻͕ՄೳʹͳΔ w ΤϯυϙΠϯτΛΦϓγϣϯࢦఆ͢Δඞཁ͋Γ w ŠFOEQPJOUVSMIUUQMPDBMIPTU $ aws

    s3 mb s3://sample --endpoint-url=http://localhost:4566 --profile LocalStack make_bucket: sample $ aws s3 cp ./sample.txt s3://sample/ --endpoint-url=http:// localhost:4566 --profile LocalStack upload: ./sample.txt to s3://sample/sample.txt $ aws s3 ls s3://sample/ --endpoint-url=http://localhost:4566 --profile LocalStack 2022-02-02 20:35:45 7 sample.txt
  21. %PDLFSޙย෇͚ %PDLFSΛఀࢭ $ docker-compose down Stopping localstack ... done Removing

    localstack ... done Removing network localstack_default $ docker volume ls DRIVER VOLUME NAME local localstack_localstack $ docker volume rm localstack_localstack DRIVER VOLUME NAME local localstack_localstack w σʔϞϯىಈ͍ͯ͠Δ%PDLFSΛࢭΊΔ w ӬଓԽ͍ͯ͠ΔϘϦϡʔϜ͕ෆཁʹͳΕ͹࡟আ w ϓϨϑΟοΫε͸؀ڥґଘʢσΟϨΫτϦ໊ʣ
  22. ·ͱΊ

  23. ࢥͬͨΑΓ΋؆୯ʹͰ͖·ͨ͠ ·ͱΊ w -PDBM4UBDLΛ࢖͏ͱ4ͷϩʔΧϧ։ൃ؀ڥ͕؆୯ʹͰ͖Δ w %PDLFS%FTLUPQͷ४උ w -PDBM4UBDLͷ%PDLFSىಈ w ϙʔτΛϗετ΁ެ։

    w σʔλͷӬଓԽ w "84༻μϛʔϓϩϑΝΠϧͷ४උ w %PDLFS$PNQPTFΛར༻͢Ε͹Ԡ༻͕ޮ͘ w -PDBM4UBDLҎ֎ͷίϯςφΛར༻ͨ͠αʔϏε΋ ಉ࣌ʹ্ཱͪ͛ͯ·ͱΊͯ։ൃ؀ڥ͕Ͱ͖Δ w (MVFษڧதͳͷͰ(MVF΋Ұॹʹىಈͯ͠ࢼ͍ͯ͠Δ w 4ޓ׵ͷπʔϧ͸NJOJPͳͲଞʹ΋͋Δ
  24. 0OFNPSFUIJOH

  25. 1ZUIPO൛ 1ZUIPO൛͸΋ͬͱָ $ pip install localstack $ lolcalstack start -d

    $ pip install awscli-local $ awslocal s3 mb s3://sample make_bucket: sample w QJQͰೖΕͯσʔϞϯΛىಈ͢Δ͚ͩ w ཪͰ%PDLFS্ཱ͕ͪΔ w BXTDMJMPDBMͰݺͼग़ͤΔ w ΤϯυϙΠϯτͷࢦఆ΍μϛʔϓϩϑΝΠϧͷ࡞੒ෆཁ w -PDBM4UBDLఀࢭͰ4ͷ৘ใ͸ফ͑Δ w *TTVFͷΛݟΔݶΓରԠ༧ఆͳͦ͞͏ʁ IUUQTHJUIVCDPNMPDBMTUBDLMPDBMTUBDLJTTVFT
  26. ஥ؒืूத ΧδϡΞϧ໘ஊ΋ͯ͠·͢ w ΠϯϑϥΤϯδχΞʢ"84  w όοΫΤϯυΤϯδχΞʢ(Pʣ w σʔλΤϯδχΞ 1IPUP1",65"40

    'POU.PSJTBXB