0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWS SAMのLambdaでS3へのPut権限をつける

Posted at

AWS SAMでLambdaの構築が便利になったものの、Hello World Exampleで作成されるテンプレにはS3の権限がついていません。

なので、S3にオブジェクトを読み書きさせたいときには、下のようにtemplate.yamlを編集して権限をつける必要があります。

Globals:
  Function:
    Timeout: 3
    MemorySize: 1000

+Parameters:
+  S3BucketName:
+    Type: String
+    Default: "アクセスしたいバケット名"

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      Architectures:
        - x86_64
+      Policies:
+        - S3WritePolicy:
+            BucketName: !Ref S3BucketName
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: ./hello_world
      DockerTag: python3.9-v1

あとはLambdaからboto3などでよしなにしましょう。

なお、今回はS3WritePolicyでしたが、もちろん他のポリシーも付けられます。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?