Objective: Create the IAM role LambdaGetStudentRole for the Lambda function
getStudentData
, granting permissions to read data from the DynamoDB tablestudentData
, log data to CloudWatch, and support potential interactions with S3 and CloudFront.
The function getStudentData performs a Scan operation to retrieve all student data (Student ID, Full Name, Class, Date of Birth, Email) from the DynamoDB table studentData
. This role needs to include:
AWSLambdaBasicExecutionRole
).AmazonDynamoDBReadOnlyAccess
).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 LambdaGetStudentRole:
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).
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 four policies:
AWSLambdaBasicExecutionRole:
AWSLambdaBasicExecutionRole
in the search bar.Description: Allows Lambda functions to log to CloudWatch for monitoring and debugging.
Figure 5: Selecting the AWSLambdaBasicExecutionRole policy.
AmazonDynamoDBReadOnlyAccess:
AmazonDynamoDBReadOnlyAccess
in the search bar.Description: Grants read-only access to DynamoDB, supporting operations like Scan or GetItem.
Figure 6: Selecting the AmazonDynamoDBReadOnlyAccess policy.
AmazonS3FullAccess:
AmazonS3FullAccess
in the search bar.Description: Grants read, write, and manage S3 buckets for potential future features (e.g., storing additional files).
Figure 7: Selecting the AmazonS3FullAccess policy.
CloudFrontFullAccess:
CloudFrontFullAccess
in the search bar.Description: Grants permission to manage CloudFront distributions for potential future features.
Figure 8: Selecting the CloudFrontFullAccess policy.
Verify the list of Permissions policies to ensure it includes:
AWSLambdaBasicExecutionRole
AmazonDynamoDBReadOnlyAccess
AmazonS3FullAccess
CloudFrontFullAccess
Click Next.
In the Role details section:
LambdaGetStudentRole
.
Note: The name must match exactly with the Lambda function configuration for
getStudentData
.
Figure 9: Enter role name and description.
Double-check:
AWSLambdaBasicExecutionRole
, AmazonDynamoDBReadOnlyAccess
, AmazonS3FullAccess
, CloudFrontFullAccess
.Click Create Role.
Figure 10: Create Role button to confirm.
After clicking Create Role, you will return to the Roles list.
Find the LambdaGetStudentRole role. If successful, you should see the message: “Role LambdaGetStudentRole created”.
Click on LambdaGetStudentRole to view details:
arn:aws:iam::your-account-id:role/LambdaGetStudentRole
) to use when configuring the Lambda function.AWSLambdaBasicExecutionRole
, AmazonDynamoDBReadOnlyAccess
, AmazonS3FullAccess
, CloudFrontFullAccess
.If the role does not appear, refresh the page or double-check the steps.
Figure 11: Role details for LambdaGetStudentRole with ARN and policies.
Factor | Details |
---|---|
Role Name | Must be LambdaGetStudentRole (case-sensitive) to match the Lambda function. Incorrect names will cause execution errors. |
S3 and CloudFront | AmazonS3FullAccess and CloudFrontFullAccess are not currently used, but kept for future functionality (e.g., storing files in S3 or managing CloudFront). Delete if unnecessary to comply with least privilege. |
Security Optimization | Consider creating a custom policy instead of AmazonDynamoDBReadOnlyAccess to restrict access specifically to the studentData table. |
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 ) or contact your administrator. |
Practical Tip: Always verify the ARN and policies immediately after creating the role to confirm configuration before integrating with Lambda.
The IAM role LambdaGetStudentRole ensures that the Lambda function getStudentData
has permissions to read data from DynamoDB, log data to CloudWatch, and support potential extensions with S3 and CloudFront. This role is now ready to be integrated into the Lambda function in the next steps.
Next Step: Proceed to Create IAM Role for Lambda Post to set up the role for the function that stores student data!