30
Ⓒ Classmethod, Inc. re:Inventで発表された AWS Lambdaの 更新情報と使い方考察 1 横山 文人 クラスメソッド株式会社 オペレーションチーム 2015年10月26日

re:Inventで発表されたAWS Lambdaの更新情報と使い方考察

Embed Size (px)

Citation preview

Ⓒ Classmethod, Inc.

re:Inventで発表された AWS Lambdaの 更新情報と使い方考察

1

横山 文人 クラスメソッド株式会社 オペレーションチーム

2015年10月26日

Ⓒ Classmethod, Inc.

自己紹介• オペレーションチーム所属 • AWS監視サービス開発担当 • 得意分野

• Python(2系) • 好きな食べもの

• サーモン!サーモン!! • Twitter

• @tututen

2

https://www.youtube.com/watch?v=Ubv7NadPSww

パネポン(対戦者募集中)

Ⓒ Classmethod, Inc.

AWS Lambda• サーバ管理が不要でコードが実行できます(Java、JavaScript)

• 継続的スケーリング • 実行時間100ms単位での課金($0.000000208/100ms ~)

• イベント駆動(S3、DynamoDB、Kinesis、SNS、etc)

4

Ⓒ Classmethod, Inc.

更新情報• Python対応 • スケジュール機能 • ロングランニング • バージョニング

年内対応予定 • VPC対応     

5

Ⓒ Classmethod, Inc.

更新情報• Python対応

• Python 2.7系(多分Amazon AMIの関係) • boto3が標準搭載

• スケジュール機能 • cron(指定時刻に実行) • rate (指定間隔で実行)

6

Ⓒ Classmethod, Inc.

更新情報• ロングランニング

• 最大実効時間が60秒→300秒(5分)まで拡大

• バージョニング • Functionの更新毎にバージョニング • aliasを張ることで、Prod、Dev等の実行切り替えが可能

7

利用例

Ⓒ Classmethod, Inc.

定期的にインスタンス起動・停止

9

サービスを選び

Pythonのブループリント選択

HandlerとRoleを設定

Write Code

Ⓒ Classmethod, Inc.

インスタンス起動スクリプト

14

Ⓒ Classmethod, Inc.

インスタンス停止スクリプト

15

Ⓒ Classmethod, Inc.

Event登録

16

Ⓒ Classmethod, Inc.

Event登録

17

Ⓒ Classmethod, Inc.

Event登録

18

Ⓒ Classmethod, Inc.

cronの引数

19

FIeld Value Wildcards

Minutes 0-59 , - * /

Hours 0-23 , - * /

Day-of-month 1-31 , - * ? / L W

Month 1-12 or JAN-DEC , - * /

Day-of-week 1-7 or SUN-SAT , - * / L #

Year 1970-2199 , - * /

cron(0 3 ? * MON-FRI *)

Ⓒ Classmethod, Inc.

rateの引数

20

Unit mean

Minutes 分

hour 時間

days 日

rate(Value Unit)

Ⓒ Classmethod, Inc.

注意点• cronの最低間隔は5分 • 指定時間はUTC(9:00 JSTで指定するなら0:00UTCで登録)

21

Ⓒ Classmethod, Inc.

Twitter Bot

22

Ⓒ Classmethod, Inc.

zip+aws cliで登録してみる

23

Ⓒ Classmethod, Inc.

zip+aws cliで登録してみる

24

Ⓒ Classmethod, Inc.

ツイートするコード

25

Ⓒ Classmethod, Inc.

zip+aws cliで登録してみる

26

Ⓒ Classmethod, Inc.

zip+aws cliで更新してみる

27

Ⓒ Classmethod, Inc.

aws cliで関数を発火してみる

28

Ⓒ Classmethod, Inc.

スケジュール機能使う場合• 「◯◯時の時これをツイート」という辞書を作っておく(UTC時間に注意)

• 分刻みで発言するなら多少幅を持たせて、内容を選べるようにする(cron前後3分とか)

• Eventsを増やすことに抵抗なければ、event[‘resources’]でEventを特定できる

29

Ⓒ Classmethod, Inc.

まとめ• Python対応で、簡単に出来る事が多くなった

• ScheduledEventのおかげでcronのEC2がいらなくなるかも

• Dev.IOの方に使用例に載っています!

30