LoginSignup
2
3

More than 3 years have passed since last update.

AWS Lambda matplotlibでグラフ作成、S3にアップロードする

Last updated at Posted at 2021-02-27

lambda

権限の問題によりtmpディレクトリ下に保存する。

lambda_function.py
import matplotlib.pyplot as plt
import boto3


def upload():
    fig = plt.figure()
    plt.plot([1, 2, 3], [4, 5, 6])
    fig.savefig('/tmp/sample.png')
    client = boto3.client('s3')
    client.upload_file(
        '/tmp/sample.png',
        'lambda-upload-test-0227',
        'sample.png'
    )

def lambda_handler(event, context):
    upload()
    return 0

matplotlibのインポート

こちらの記事を参考にmatplotlibのARNをレイヤーに追加する。

参考記事

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3