Creating an IAM Policy for Lambda Function

In this section, we will create an IAM Policy to grant permissions for the Lambda Function to perform operations with objects in S3 buckets.

Create IAM Policy

  1. Navigate to Lambda Function resize-image
    • Go to the Configuration tab
    • Select Permissions from the left menu
    • Click on the role attached to the function

CreatePolicy

  1. On the IAM Role resize-image-role-… page:
    • Click Add permissions
    • Select Create inline policy

CreatePolicy

  1. On the Specify permissions page:
    • Search and select the S3 service

CreatePolicy

  • In the search box, enter GetObject
  • Check the GetObject permission in the Read group

CreatePolicy

  • Clear the search keyword and enter DeleteObject
  • Check the DeleteObject permission in the Write group
  • In the Resources section, select Specific
  • Click Add ARNs to restrict access

CreatePolicy

  • In the Specify ARNs dialog:
    • Enter book-image-stores-tranvix in the Resource bucket name field
    • Check Any object name or enter * in the Resource object name field
    • Click Add ARNs

CreatePolicy

  • Click + Add more permissions
  • Select the S3 service again

CreatePolicy

  • Find and select the PutObject permission in the Write group
  • Click Add ARNs to restrict access

CreatePolicy

  • In the Specify ARNs dialog:
    • Enter book-image-resize-stores-tranvix in the Resource bucket name field
    • Enter * in the Resource object name field
    • Click Add ARNs

CreatePolicy

  • Click Next

CreatePolicy

  1. On the Review and create page:
    • Name the policy LambdaResizeImageS3Policy
    • Review the policy configuration and click Create policy

CreatePolicy

  1. Verify the newly created policy in the list

CreatePolicy

You have now completed granting permissions to the Lambda Function to interact with objects in S3 buckets. The next step is to test the Lambda Function by uploading a test image file.