Create Policy for Lambda function

In this part, we will create a Policy that grants the Lambda function permission to get, write, and delete objects in the S3 bucket.

  1. Navigate to console of created in step 1 Lambda function.
  • In tab Configuration, click Permissions
  • Click on the role being executed by the function

CreatePolicy

  1. Click Add permissions
  • Select Attach policies

CreatePolicy

  1. Click Create policy

CreatePolicy

  1. Click Choose a service

CreatePolicy

  1. Enter S3, then select S3

CreatePolicy

  1. Click Action, expand Read in Access level
  • Check to GetObject permission

CreatePolicy

  1. Then, expand Write
  • Check to DeleteObject permission

CreatePolicy

  1. In Resource, click Add ARN to specify resources.

CreatePolicy

  1. Enter bucket name: book-image-store
  • Check to Any to allow permissions for all objects in the bucket
  • Click Add

CreatePolicy

  1. Click Add additional permissions

CreatePolicy

  1. Repeat steps 4 and 5
  • Then, expand Write, check to PutObject permission

CreatePolicy

  1. Repeat steps 8 and 9 with bucket name is book-image-resize-store

CreatePolicy

  1. Click Next tags

CreatePolicy

  1. Click Next review
  2. Enter policy name, such as: LambdaResizeImageS3Policy
  • Review policy information and click Create policy

CreatePolicy

  1. Back to adding policy for Lambda function screen, enter the name of the policy we just created.
  • Check to the policy: LambdaResizeImageS3Policy
  • Click Attach policies

CreatePolicy

We have finished granting the Lambda function read, write, and delete permissions from the S3 bucket. The next step is to test the Lambda function working when uploading an image.