Creating an IAM Policy for Lambda Function

This section guides you through creating an IAM Policy that grants your Lambda function the necessary permissions to perform get, put, and delete operations on objects in your S3 buckets.

Configure Lambda Function Permissions

  1. Navigate to your Lambda function configuration:

    • Open the resize-image function
    • Select the Configuration tab
    • Click on Permissions
    • Click the execution role name to access IAM Lambda Permissions
  2. Create a new inline policy:

    • In the IAM role page, select Add permissions
    • Choose Create inline policy Create Inline Policy

Define S3 Permissions

  1. Configure source bucket permissions:

    • Select Choose a service and search for S3
    • Click S3 to select the service Select S3 Service
    • Search for and select GetObject under Read actions GetObject Permission
    • Clear the search and add DeleteObject under Write actions
    • Select Add ARNs to specify the resource DeleteObject Permission
    • In the Specify ARNs dialog:
      • Set Resource bucket name to book-image-stores-by-myself
      • Enter * for Resource object name
      • Confirm with Add ARNs Source Bucket ARN
  2. Configure destination bucket permissions:

    • Select + Add more permissions
    • Choose S3 service again Add More Permissions
    • Search for and select PutObject under Write actions
    • Click Add ARNs PutObject Permission
    • In the Specify ARNs dialog:
      • Set Resource bucket name to book-image-resize-stores-by-myself
      • Enter * for Resource object name
      • Click Add ARNs
    • Proceed by clicking Next Destination Bucket ARN

Review and Create Policy

  1. Finalize the policy:

    • Name your policy (e.g., LambdaResizeImageS3Policy)
    • Review the permissions configuration
    • Click Create policy to finish Create IAM Policy
  2. Verify the newly created policy in the role’s permission list Verify Policy

You have now successfully configured the IAM policy granting your Lambda function the required permissions to interact with both S3 buckets. The next step is to test the Lambda function by uploading an image to verify the complete workflow.