Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
AWS SDK for GoのContextパターン / aws sdk for go con...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Shuichi Ohsawa
May 28, 2018
Programming
830
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AWS SDK for GoのContextパターン / aws sdk for go context pattern
Shuichi Ohsawa
May 28, 2018
More Decks by Shuichi Ohsawa
See All by Shuichi Ohsawa
実践的データ基盤への処方箋 輪読会 / round-reading-jissennteki-data-kiban
ohsawa0515
1
270
datatech-jp Casual Talks #1 「BigQueryのネイティブJSON型がサポートされたので触ってみた」 / support-bigquery-native-json-and-try-it
ohsawa0515
0
2.8k
技書博後夜祭 第一夜「AWSのコスト最適化をはじめよう!」 / gishohaku5-koyasai-starting-aws-cost-optimization
ohsawa0515
0
430
JAWS-UG 初心者支部#36 「AWSで高額請求やらかした話」 / story-about-high-billing-on-aws
ohsawa0515
0
1.4k
インフラエンジニアBooks #7 「Amazon Web Servicesコスト最適化入門」 / infra-engineer-books-aws-cost-optimization
ohsawa0515
12
5.2k
ECSでGPUを使う 2020年版 / jawsug-container18-lt-using-gpu-on-ecs-2020
ohsawa0515
0
2.4k
急成長するシステムに追いつくためのインフラ改善への取り組み / sansan-m3-tech-night-improve-infrastructure
ohsawa0515
0
3k
インフラエンジニアがConsulとStretcherをつかったデプロイ改善で開発効率の向上に貢献した話(短縮版 + α) / omotesando.rb #33
ohsawa0515
0
1.1k
サーバレスVulsアーキテクチャ再び / serverless-vuls-again
ohsawa0515
1
4.2k
Other Decks in Programming
See All in Programming
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
170
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
540
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
530
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
150
初めてのKubernetes 本番運用でハマった話
oku053
0
130
継続モナドとリアクティブプログラミング
yukikurage
3
640
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
180
霧の中の代数的エフェクト
funnyycat
1
430
今さら聞けない .NET CLI
htkym
0
120
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
350
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
190
AIが無かった頃の素敵な出会いの話
codmoninc
1
220
Featured
See All Featured
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.6k
Navigating Weather and Climate Data
rabernat
0
400
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
410
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Designing Experiences People Love
moore
143
24k
Discover your Explorer Soul
emna__ayadi
2
1.2k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
590
Making the Leap to Tech Lead
cromwellryan
135
10k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
520
The World Runs on Bad Software
bkeepers
PRO
72
12k
Transcript
AWS SDK for Goͷ Contextύλʔϯ Gopherಓ #1 LT Shuichi Ohsawa
(@ohsawa0515) 1/13
ࣗݾհ • େᖒलҰ(Shuichi Ohsawa) • GitHub, Twitter: @ohsawa0515 • Blog:
http://blog.jicoman.info/ • Sansanגࣜձࣾ - ໊ཧΫϥυαʔϏε • ໊σʔλԽγεςϜͷΠϯϑϥߏஙɾӡ༻ɾվળ 2/13
AWS SDK for Go ͷ υΩϡϝϯτΛ ݟ͍ͯͯؾ͍ͮͨ 3/13
4/13
5/13
ContextΛΔલ WithContextͬͯͳΜͩΖ͏ŋŋŋ ❓ GoݴޠͷContextΛ͏Έ͍͚ͨͩͲɺαϯϓϧίʔυݟͯ ͬͯͳͦ͞͏ͩ͠ผʹ͍͍ " 6/13
ContextΛͬͨޙ Ωϟϯηϧͱ͔λΠϜΞτ͕Ͱ͖Δ͔ΒศརΜ 7/13
S3ΞοϓϩʔυʹλΠϜΞτΛઃ ͚Δ ctx, cancel := context.WithTimeout(context.Background(), time.Duration(30)*time.Second) defer cancel() svc
:= s3.New(sess) if _, err := svc.PutObjectWithContext(ctx, &s3.PutObjectInput{ Body: f, Bucket: aws.String(s3Bucket), Key: aws.String(file), }); err != nil { log.Fatal(err) } 8/13
PutObjectWithContext() PutObject() ʹ ContextΛηοτ͍ͯ͠Δ func (c *S3) PutObjectWithContext(ctx aws.Context, input
*PutObjectInput, opts ...request.Option) (*PutObjectOutput, error) { req, out := c.PutObjectRequest(input) req.SetContext(ctx) req.ApplyOptions(opts...) return out, req.Send() } 9/13
PutObjectWithContext() PutObject() ʹͳ͍Ҿ͕ŋŋŋ func (c *S3) PutObjectWithContext(ctx aws.Context, input *PutObjectInput,
opts ...request.Option) (*PutObjectOutput, error) { req, out := c.PutObjectRequest(input) req.SetContext(ctx) req.ApplyOptions(opts...) return out, req.Send() } 10/13
ϦΫΤετϋϯυϥΛڬΊΔ PutObjectʹ͔͔ͬͨ࣌ؒΛදࣔ͢Δ ctx, cancel := context.WithTimeout(context.Background(), time.Duration(30)*time.Second) defer cancel() svc
:= s3.New(sess) if _, err := svc.PutObjectWithContext(ctx, &s3.PutObjectInput{ Body: f, Bucket: aws.String(s3Bucket), Key: aws.String(file), }, func(r *request.Request) { start := time.Now() r.Handlers.Complete.PushBack(func(req *request.Request) { fmt.Printf("request %s took %s to complete\n", req.RequestID, time.Since(start)) }) }); err != nil { log.Fatal(err) } 11/13
·ͱΊ • AWS SDK for GoͷContextύλʔϯΛ͑APIίʔϧͷ ΩϟϯηϧλΠϜΞτΛ؆୯ʹઃఆͰ͖Δ • SDKଆͰΩϟϯηϧॲཧΛͤΔ͜ͱ͕Ͱ͖ΔͷͰɺContext ͱ΄΅࣮͕มΘΒͣ͑Δ
• ϦΫΤετϋϯυϥΛڬΊΔͷͰଞʹ͍Ζ͍ΖͰ͖ͦ͏ 12/13
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝ ·ͨ͠ 13/13