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
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
160
メールのエイリアス機能を履き違えない
isshinfunada
0
230
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.7k
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
380
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
450
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
180
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
400
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
550
「人を評価する AI」の設計と実装
ryoyanara
0
180
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
540
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
150
プロポーザルを書いてもらう
pvcresin
0
290
Featured
See All Featured
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
570
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
690
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
470
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
410
エンジニアに許された特別な時間の終わり
watany
108
250k
Automating Front-end Workflow
addyosmani
1370
210k
From π to Pie charts
rasagy
0
260
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
390
Chasing Engaging Ingredients in Design
codingconduct
0
260
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
Writing Fast Ruby
sferik
630
63k
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