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
820
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.7k
技書博後夜祭 第一夜「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.3k
急成長するシステムに追いつくためのインフラ改善への取り組み / 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.1k
Other Decks in Programming
See All in Programming
Lessons from Spec-Driven Development
simas
PRO
0
210
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
410
A2UI という光を覗いてみる
satohjohn
1
140
Contextとはなにか
chiroruxx
1
330
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
170
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
100
Oxcを導入して開発体験が向上した話
yug1224
4
320
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
120
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
11
5.9k
Webフレームワークの ベンチマークについて
yusukebe
0
170
Creating Composable Callables in Contemporary C++
rollbear
0
150
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.3k
Featured
See All Featured
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
340
WCS-LA-2024
lcolladotor
0
650
Building a Scalable Design System with Sketch
lauravandoore
463
34k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
430
We Have a Design System, Now What?
morganepeng
55
8.2k
How to Talk to Developers About Accessibility
jct
2
240
How to make the Groovebox
asonas
2
2.2k
Believing is Seeing
oripsolob
1
150
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
230
WENDY [Excerpt]
tessaabrams
11
38k
It's Worth the Effort
3n
188
29k
How GitHub (no longer) Works
holman
316
150k
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