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

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

- On the Specify permissions page:
- Search and select the S3 service

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

- 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

- 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

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

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

- 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


- On the Review and create page:
- Name the policy LambdaResizeImageS3Policy
- Review the policy configuration and click Create policy

- Verify the newly created policy in the list

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.