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
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
280
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
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
550
PyO3 で既存 Python 評価器を Rust core 化する ー wasm-bindgen でブラウザにも配るための設計
kdash
1
150
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
440
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.9k
「つくるAI」だけではバグは見つからない ~テストに必要な「見つけるAI」を分離させる戦略~
mfunaki
0
220
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
130
Deep dive into the select statement (GopherCon UK)
jespino
0
160
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
460
Press start. Python's next generation.
willingc
PRO
3
300
Cloudflare is Agents
chimame
0
190
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
2
1.4k
이 함수, 실패하면 어떻게 되나요? null부터 Rich Errors까지, Kotlin 에러 처리 15년
haeti2
0
110
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
37
3.9k
Are puppies a ranking factor?
jonoalderson
2
3.9k
Amusing Abliteration
ianozsvald
1
280
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
490
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
510
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Utilizing Notion as your number one productivity tool
mfonobong
4
560
Git: the NoSQL Database
bkeepers
PRO
432
67k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
360
How STYLIGHT went responsive
nonsquared
100
6.3k
Typedesign – Prime Four
hannesfritz
42
3.2k
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