Objective: Create the IAM role LambdaInsertStudentRole for the Lambda function
insertStudentData
, granting permissions to write data to the DynamoDB tablestudentData
, send emails via AWS SES, log data to CloudWatch, and support potential interactions with S3 and CloudFront.
The function insertStudentData performs:
studentData
via the PutItem operation.This role needs:
AWSLambdaBasicExecutionRole
).AmazonDynamoDBFullAccess
).AmazonSESFullAccess
).AmazonS3FullAccess
, CloudFrontFullAccess
) for potential future features.Note:
AmazonS3FullAccess
andCloudFrontFullAccess
are not currently used in the code, but are retained for future functionalities (e.g., saving files to S3 or managing CloudFront).
Below are the detailed steps to create the IAM role LambdaInsertStudentRole:
Open your browser and log in to the AWS Management Console with your AWS account.
In the search bar at the top of the page, type IAM and select Identity and Access Management (IAM).
Ensure you are in the correct AWS region (e.g., us-east-1
), check in the top right corner.
Figure 1: AWS Console interface with the IAM search bar.
In the IAM interface, find the left-hand navigation menu.
Select Roles to view the list of IAM roles. If no roles exist, the list will be empty.
Figure 2: Navigation menu with the Roles option.
In the Roles interface, click the Create Role button in the top-right corner.
Figure 3: Create Role button in the Roles interface.
In the Select trusted entity section, choose AWS Service to specify that the role is for an AWS service.
In the Use case section, select Lambda from the list of services.
Click Next to move to the permission configuration step.
Figure 4: Choosing AWS Service and Lambda in Use case.
In the Permissions section, add the following policies:
AWSLambdaBasicExecutionRole:
AWSLambdaBasicExecutionRole
in the search bar.Description: Allows the Lambda function to log to CloudWatch for monitoring and debugging.
Figure 5: Selecting the AWSLambdaBasicExecutionRole policy.
AmazonDynamoDBFullAccess:
AmazonDynamoDBFullAccess
in the search bar.Description: Grants read and write access to DynamoDB, including the PutItem operation required for the
insertStudentData
function.
Figure 6: Selecting the AmazonDynamoDBFullAccess policy.
AmazonSESFullAccess:
AmazonSESFullAccess
in the search bar.Description: Grants permission to send emails via SES to send confirmation notifications (e.g., to
nguyentribaothang@gmail.com
).
Figure 7: Selecting the AmazonSESFullAccess policy.
AmazonS3FullAccess (optional):
AmazonS3FullAccess
in the search bar.Description: Grants read, write, and manage S3 buckets for potential future features.
Figure 8: Selecting the AmazonS3FullAccess policy.
CloudFrontFullAccess (optional):
CloudFrontFullAccess
in the search bar.Description: Grants permission to manage CloudFront distributions for potential future features.
Figure 9: Selecting the CloudFrontFullAccess policy.
Verify the list of Permissions policies to ensure it includes:
AWSLambdaBasicExecutionRole
AmazonDynamoDBFullAccess
AmazonSESFullAccess
AmazonS3FullAccess
CloudFrontFullAccess
Click Next.
In the Role details section:
LambdaInsertStudentRole
.
Note: The name must match exactly with the Lambda function configuration for
insertStudentData
.
Figure 10: Enter role name and description.
Double-check:
AWSLambdaBasicExecutionRole
, AmazonDynamoDBFullAccess
, AmazonSESFullAccess
, AmazonS3FullAccess
, CloudFrontFullAccess
.Click Create Role.
After clicking Create Role, you will return to the Roles list.
Figure 11: Click Create Role to finalize the creation.
Find the LambdaInsertStudentRole role. If successful, you should see the message: “Role LambdaInsertStudentRole created”.
Figure 12: Success message for the LambdaInsertStudentRole creation.
Click on LambdaInsertStudentRole to view details:
arn:aws:iam::your-account-id:role/LambdaInsertStudentRole
) to use when configuring the Lambda function.If the role does not appear, refresh the page or check the steps again.
Factor | Details |
---|---|
Role Name | Must be LambdaInsertStudentRole (case-sensitive) to match the Lambda function. Incorrect names will cause execution errors. |
DynamoDB Permissions | AmazonDynamoDBReadOnlyAccess does not support PutItem . Use AmazonDynamoDBFullAccess to allow PutItem on the studentData table. |
S3 and CloudFront | AmazonS3FullAccess and CloudFrontFullAccess are not currently used, but are retained for potential future functionalities (e.g., saving files to S3 or managing CloudFront). Delete if unnecessary to comply with least privilege. |
Check Early | Record the ARN and verify the role in IAM before configuring the Lambda function to ensure proper setup. |
Error Handling | If you encounter an “Access Denied” error, check AWS account permissions (iam:CreateRole , iam:AttachRolePolicy ) or contact your administrator. If the function reports AccessDenied , check the DynamoDB policy. Use CloudTrail or IAM Access Advisor to pinpoint the issue. |
AWS Region | Ensure the AWS region (e.g., us-east-1 ) is consistent with other services (DynamoDB, Lambda, SES). Check in the top right corner of the AWS Console. |
Practical Tip: Always verify the role and ARN immediately after creation to confirm correct configuration before integrating with the Lambda function.
The IAM role LambdaInsertStudentRole ensures that the Lambda function insertStudentData
has the necessary permissions to write data to DynamoDB, send emails via SES, and log data to CloudWatch, while supporting future extensions with S3 and CloudFront. With AmazonDynamoDBFullAccess
, the function operates efficiently and securely in a serverless application.
Next Step: Proceed to Create IAM Role for DynamoDB Backup to set up the role for data backup!