LoginSignup
1
0

More than 3 years have passed since last update.

AWS Lambdaでファイルを作成・編集しS3にアップロードする

Last updated at Posted at 2021-02-27

サンプルコード

  • Body・・・ファイルに書きたい内容
  • Bucket・・・アップロード先のバケット
  • Key・・・アップロードしたときのファイル名
lambda_function.py
import boto3

def upload():
    client = boto3.client('s3')
    response = client.put_object(
        Body='Hello from Lambda!',
        Bucket='my-bucket',
        Key='sample.txt',
    )

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

サンプルロール

既存のラムダロールに追加する。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::my-bucket/*"
    }
  ]
}

参考記事

  • boto3 ドキュメント

1
0
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
1
0