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
Pythonで書かれたマイクロサービスを2to3した
Search
iwamot
PRO
April 14, 2022
Technology
0
860
Pythonで書かれたマイクロサービスを2to3した
2022-04-14
みんなのPython勉強会 #80 懇親会
https://startpython.connpass.com/event/242556/
iwamot
PRO
April 14, 2022
Tweet
Share
More Decks by iwamot
See All by iwamot
AIエージェント・マイクロサービス時代。AWSでの手軽な構築法を考えて試してみた
iwamot
PRO
1
47
これがLambdaレス時代のChatOpsだ!実例で学ぶAmazon Q Developerカスタムアクション活用法
iwamot
PRO
9
1.5k
Developer Certificate of Origin、よさそう
iwamot
PRO
0
40
復号できなくなると怖いので、AWS KMSキーの削除を「面倒」にしてみた CODT 2025 クロージングイベント版
iwamot
PRO
1
130
復号できなくなると怖いので、AWS KMSキーの削除を「面倒」にしてみた
iwamot
PRO
3
100
IPA&AWSダブル全冠が明かす、人生を変えた勉強法のすべて
iwamot
PRO
14
11k
2年でここまで成長!AWSで育てたAI Slack botの軌跡
iwamot
PRO
4
1.2k
名単体テスト 禁断の傀儡(モック)
iwamot
PRO
1
610
クォータ監視、AWS Organizations環境でも楽勝です✌️
iwamot
PRO
2
610
Other Decks in Technology
See All in Technology
AzureでのIaC - Bicep? Terraform? それ早く言ってよ会議
torumakabe
1
390
Introduction to Bill One Development Engineer
sansan33
PRO
0
360
セキュリティについて学ぶ会 / 2026 01 25 Takamatsu WordPress Meetup
rocketmartue
1
290
ファインディの横断SREがTakumi byGMOと取り組む、セキュリティと開発スピードの両立
rvirus0817
1
1.2k
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
13k
CDK対応したAWS DevOps Agentを試そう_20260201
masakiokuda
1
200
クレジットカード決済基盤を支えるSRE - 厳格な監査とSRE運用の両立 (SRE Kaigi 2026)
capytan
6
2.6k
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
68k
今日から始めるAmazon Bedrock AgentCore
har1101
4
400
Frontier Agents (Kiro autonomous agent / AWS Security Agent / AWS DevOps Agent) の紹介
msysh
3
150
MCPでつなぐElasticsearchとLLM - 深夜の障害対応を楽にしたい / Bridging Elasticsearch and LLMs with MCP
sashimimochi
0
140
Tebiki Engineering Team Deck
tebiki
0
24k
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.1k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
290
Un-Boring Meetings
codingconduct
0
200
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
410
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
97
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
160
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
Testing 201, or: Great Expectations
jmmastey
46
8k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
110
WCS-LA-2024
lcolladotor
0
450
GitHub's CSS Performance
jonrohan
1032
470k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Transcript
Pythonで書かれたマイクロサービスを 2to3した 2022-04-14 みんなのPython勉強会 #80 懇親会 https://startpython.connpass.com/event/242556/ Takashi Iwamoto (@iwamot)
技術的負債を解消したくて転職した 昨夏、AWS Japanを辞めてENECHANGE株式会社に転職した 面接時に「技術的負債の解消に取り組みたい」と明言した 内定をもらえ、負債の解消がミッションのひとつとなった
Python 2のコードがあった Elastic BeanstalkのDockerコンテナで動いているFlaskアプリ Lambdaに移行すればコストを減らせる LambdaではPython2のサポートが終わっている
Python 3に上げることにした 「移行に取り組みたい」と手を挙げ、OKをもらった
テストを走らせたらfailした 9%のテストケースがfailした パフォーマンス向上のためのコード改善が原因だった
passするように直した テストケースとソースコードを修正した カバレッジは80%と高めだった
2to3というツールがあることを知った 2to3 - Python 2 から 3 への自動コード変換 https://docs.python.org/ja/3/library/2to3.html Python
3の公式Dockerイメージにも2to3が含まれている $ docker run -it --rm python:3 2to3 --help | head -1 Usage: 2to3 [options] file|dir ...
2to3を実行したら、色々変換された (1) dict - dict.values() + list(dict.values()) - dict.iteritems() +
dict.items() except - except Exception, e: + except Exception as e:
2to3を実行したら、色々変換された (2) has_key - dict.has_key(key) + key in dict import
- import weather + from . import weather
2to3を実行したら、色々変換された (3) imports - import ConfigParser + import configparser print
- print 'foo' + print('foo')
2to3を実行したら、色々変換された (4) unicode - u'foo' + 'foo' xrange - range(1,
13) + list(range(1, 13))
必要ない変換は元に戻した たとえばdictによる変換は不要だった - list(dict.values()) + dict.values() Python 2では dict.values() はリストを返す
Python 3では dict.values() はビューオブジェクトを返す ビューオブジェクトのまま処理できるなら、そのままでよい
あとは手作業で進めた 依存パッケージのアップグレード テストがfailする部分の修正 Lambda対応
2to3があってよかった 初見から数日で移行できた こういう移行ツールが用意されていると助かる
負債に困ったらご相談ください Spot Resourceという屋号で副業しています https://iwamot.github.io/