{"id":71950,"date":"2019-05-24T15:16:05","date_gmt":"2019-05-24T15:16:05","guid":{"rendered":"https:\/\/www.whizlabs.com\/blog\/?p=71950"},"modified":"2020-08-31T17:52:05","modified_gmt":"2020-08-31T17:52:05","slug":"iam-roles-for-aws-lambda-function","status":"publish","type":"post","link":"https:\/\/www.whizlabs.com\/blog\/iam-roles-for-aws-lambda-function\/","title":{"rendered":"Understanding IAM Roles for AWS Lambda Function"},"content":{"rendered":"<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">The AWS Lambda service is the serverless compute service on the cloud. Now if the AWS Lambda function needs to access other resources then the IAM Role that is attached to the Lambda function needs to have the required access. <\/span><span style=\"font-weight: 400;\">This article discusses IAM Roles for AWS Lambda Function that is an important topic under the domain Identity and Access Management (IAM). This topic will help those who are preparing for the <a href=\"https:\/\/www.whizlabs.com\/aws-solutions-architect-professional\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Certified Solutions Architect Professional Exam<\/a> or <a href=\"https:\/\/www.whizlabs.com\/aws-certified-security-specialty\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Certified Security Specialty Exam<\/a>.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">A common type of question that comes up in the AWS certification exam is the permissions that can be assigned to an AWS Lambda function.<\/span><\/p>\n<p><a href=\"https:\/\/www.whizlabs.com\/blog\/aws-lambda-and-api-gateway-training-course\/\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"wp-image-72217 size-full aligncenter\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/AWS_Lambda_API_Gateway.gif\" alt=\"AWS Lambda and API Gateway training course\" width=\"728\" height=\"90\" \/><\/a><\/p>\n<h2 style=\"text-align: justify;\">IAM Roles for AWS Lambda Function<\/h2>\n<p>Let&#8217;s understand IAM roles for AWS Lambda function through an example:<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">In this example, we will make AWS Lambda run an AWS Athena query against a CSV file in S3. And we will see what is required from an IAM Role perspective.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Step 1) So first, we have an S3 bucket defined as shown below<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71951 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-1.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"641\" height=\"509\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-1.png 641w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-1-300x238.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-1-529x420.png 529w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-1-640x508.png 640w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">The S3 bucket has a data file called data.csv which is a simple data file which contains the name of AWS certification exams.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Step 2) Now we go onto AWS Athena. Here we have a database called demodb. We execute the following query to create a table.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Here we execute the following query:<\/span><\/p>\n<pre style=\"text-align: justify;\"><span style=\"font-weight: 400;\">CREATE EXTERNAL TABLE IF NOT EXISTS exams (<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0ID INT,<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0name STRING<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde' <\/span>\r\n\r\n<span style=\"font-weight: 400;\">WITH SERDEPROPERTIES (\"separatorChar\" = \",\") <\/span>\r\n\r\n<span style=\"font-weight: 400;\">LOCATION 's3:\/\/athena2020\/'<\/span><\/pre>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71952 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-2.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"777\" height=\"372\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-2.png 777w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-2-300x144.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-2-768x368.png 768w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-2-640x306.png 640w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-2-681x326.png 681w\" sizes=\"(max-width: 777px) 100vw, 777px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Once you run the query, you will get the table created in AWS Athena<\/span><\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"alignnone wp-image-71953 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-3.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"396\" height=\"432\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-3.png 396w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-3-275x300.png 275w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-3-385x420.png 385w\" sizes=\"(max-width: 396px) 100vw, 396px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Step 3) Now let\u2019s run a select query in AWS Athena just to check if we are able to fetch the data.<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71954 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-4.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"778\" height=\"497\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-4.png 778w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-4-300x192.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-4-768x491.png 768w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-4-657x420.png 657w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-4-640x409.png 640w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-4-681x435.png 681w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">So, you will see the result data. This is the result data that is stored in the .csv file in S3.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Step 4) Now create an AWS Lambda function. This will have python as the underlying runtime.<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71955 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-5.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"782\" height=\"347\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-5.png 782w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-5-300x133.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-5-768x341.png 768w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-5-640x284.png 640w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-5-681x302.png 681w\" sizes=\"(max-width: 782px) 100vw, 782px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Following is the code snippet<\/span><\/p>\n<pre style=\"text-align: justify;\"><span style=\"font-weight: 400;\">import json<\/span>\r\n\r\n<span style=\"font-weight: 400;\">import time<\/span>\r\n\r\n<span style=\"font-weight: 400;\">import boto3<\/span>\r\n\r\n\r\n\r\n\r\n<span style=\"font-weight: 400;\">def lambda_handler(event, context):<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0# TODO implement<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0client = boto3.client('athena')<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0query='select * from exams;'<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0S3_OUTPUT='s3:\/\/athena2020\/output'<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0# Execution<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0response = client.start_query_execution(<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0QueryString=query,<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0QueryExecutionContext={<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'Database': 'demodb'<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ResultConfiguration={<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'OutputLocation': S3_OUTPUT,<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0)<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0time.sleep(5)<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0query_execution_id = response['QueryExecutionId']<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0print(query_execution_id)<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0result = client.get_query_results(QueryExecutionId=query_execution_id)<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0print(result)<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0return {<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'statusCode': 200,<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'body': json.dumps('Results from Lambda!')<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0}<\/span><\/pre>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">The code snippet is quite self-explanatory. We are using the python boto3 SDK to work with Athena queries. We then transfer the output results to the S3 folder location &#8216;s3:\/\/athena2020\/output&#8217;. This is important to note.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Now if you drill further down, you will see the IAM Role attached to the Lambda function<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71956 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-6.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"675\" height=\"365\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-6.png 675w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-6-300x162.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-6-640x346.png 640w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">So, it\u2019s a service role called athenarole.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">If we go to the Role definition in Security credentials, you can see that the role has a basic execution policy<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71957 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-7.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"748\" height=\"388\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-7.png 748w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-7-300x156.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-7-640x332.png 640w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-7-681x353.png 681w\" sizes=\"(max-width: 748px) 100vw, 748px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Step 5) Let\u2019s run our AWS Lambda function<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71958 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-8.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"766\" height=\"233\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-8.png 766w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-8-300x91.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-8-640x195.png 640w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-8-681x207.png 681w\" sizes=\"(max-width: 766px) 100vw, 766px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">So, when we Test our AWS Lambda function, we are getting an <\/span><i><span style=\"font-weight: 400;\">Access Denied<\/span><\/i><span style=\"font-weight: 400;\"> error. This is because we need to give permission to our AWS Lambda function to access the Athena service. Since the lambda function is making a call to AWS Athena, we need to add this permission to the role.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Step 6) So let\u2019s go back to the IAM Role definition and click on Attach policies<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71959 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-9.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"788\" height=\"336\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-9.png 788w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-9-300x128.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-9-768x327.png 768w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-9-640x273.png 640w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-9-681x290.png 681w\" sizes=\"(max-width: 788px) 100vw, 788px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">For the purpose of this demo, let\u2019s just add a policy for full access to AWS Athena<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">So in the next screen, find and choose<\/span><i><span style=\"font-weight: 400;\"> AmazonAthenaFullAccess <\/span><\/i><span style=\"font-weight: 400;\">and choose Attach policy<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71960 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-10.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"755\" height=\"397\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-10.png 755w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-10-300x158.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-10-640x337.png 640w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-10-681x358.png 681w\" sizes=\"(max-width: 755px) 100vw, 755px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Step 7) Now let\u2019s run our Lambda function again<\/span><\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"alignnone wp-image-71961 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-11.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"761\" height=\"214\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-11.png 761w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-11-300x84.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-11-640x180.png 640w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-11-681x192.png 681w\" sizes=\"(max-width: 761px) 100vw, 761px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">We are still getting the same error. Why is that?<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Remember that the function also sends the output data to S3, hence we need to also ensure that the IAM role also has access to S3<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\"> Step 8) So let\u2019s go back to the IAM Role definition and click on Attach policies<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71962 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-12.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"752\" height=\"319\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-12.png 752w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-12-300x127.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-12-640x271.png 640w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-12-681x289.png 681w\" sizes=\"(max-width: 752px) 100vw, 752px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">For the purpose of this demo, let\u2019s just add a policy for full access to AWS S3<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">So in the next screen, find and choose <\/span><i><span style=\"font-weight: 400;\">AmazonS3FullAccess<\/span><\/i><span style=\"font-weight: 400;\"> and choose Attach policy<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Now let\u2019s run our AWS Lambda function<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71963 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-13.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"789\" height=\"147\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-13.png 789w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-13-300x56.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-13-768x143.png 768w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-13-640x119.png 640w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-13-681x127.png 681w\" sizes=\"(max-width: 789px) 100vw, 789px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">You will now get a successful execution of the Lambda function<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-71964 size-full\" src=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-14.png\" alt=\"IAM Roles for AWS Lambda Function\" width=\"806\" height=\"384\" srcset=\"https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-14.png 806w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-14-300x143.png 300w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-14-768x366.png 768w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-14-640x305.png 640w, https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM-AWS-Lambda-14-681x324.png 681w\" sizes=\"(max-width: 806px) 100vw, 806px\" \/><\/p>\n<h3 style=\"text-align: justify;\">Summary<\/h3>\n<ul style=\"text-align: justify;\">\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">There is a service linked role which is present for AWS Lambda functions<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">These roles have permissions which are required to access other AWS services<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">You can attach multiple policies to IAM Roles for AWS Lambda function<\/span><\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">So, here we&#8217;ve covered IAM Roles with AWS Lambda Function. Hope this helps in your preparation of AWS certification exams specifically, AWS Certified Solutions Architect Professional &amp; AWS Certified Security Specialty Exams. If you are done with your preparation, it&#8217;s the time to check your preparation level. Try Whizlabs practice tests for the <a href=\"https:\/\/www.whizlabs.com\/aws-solutions-architect-professional\/practice-tests\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Certified Solutions Architect Professional Exam<\/a> and <a href=\"https:\/\/www.whizlabs.com\/aws-certified-security-specialty\/practice-test\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Certified Security Specialty Exam<\/a>.\u00a0<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Whizlabs practice tests have been prepared by the industry experts and make you confident enough to pass the actual certification exams.\u00a0<\/span><\/p>\n<p><em>If you have any other query regarding the <span style=\"font-weight: 400;\">AWS Certified Solutions Architect Professional Exam or AWS Certified Security Specialty Exam, just put a comment below or write in <a href=\"http:\/\/ask.whizlabs.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Whizlabs Forum<\/a>.<\/span><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The AWS Lambda service is the serverless compute service on the cloud. Now if the AWS Lambda function needs to access other resources then the IAM Role that is attached to the Lambda function needs to have the required access. This article discusses IAM Roles for AWS Lambda Function that is an important topic under the domain Identity and Access Management (IAM). This topic will help those who are preparing for the AWS Certified Solutions Architect Professional Exam or AWS Certified Security Specialty Exam. A common type of question that comes up in the AWS certification exam is the permissions [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":71966,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[4],"tags":[230,240,1971,1972,1973,921],"class_list":["post-71950","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws-certifications","tag-aws-certified-security-specialty","tag-aws-certified-solutions-architect-professional","tag-aws-lambda-service","tag-iam-roles","tag-iam-roles-for-aws-lambda-function","tag-identity-and-access-management"],"uagb_featured_image_src":{"full":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",600,315,false],"thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function-150x150.png",150,150,true],"medium":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function-300x158.png",300,158,true],"medium_large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",600,315,false],"large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",600,315,false],"1536x1536":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",600,315,false],"2048x2048":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",600,315,false],"profile_24":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",24,13,false],"profile_48":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",48,25,false],"profile_96":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",96,50,false],"profile_150":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",150,79,false],"profile_300":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",300,158,false],"tptn_thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function-250x250.png",250,250,true],"web-stories-poster-portrait":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",600,315,false],"web-stories-publisher-logo":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",96,50,false],"web-stories-thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2019\/05\/IAM_Roles_for_Lambda_Function.png",150,79,false]},"uagb_author_info":{"display_name":"Pavan Gumaste","author_link":"https:\/\/www.whizlabs.com\/blog\/author\/pavan\/"},"uagb_comment_info":0,"uagb_excerpt":"The AWS Lambda service is the serverless compute service on the cloud. Now if the AWS Lambda function needs to access other resources then the IAM Role that is attached to the Lambda function needs to have the required access. This article discusses IAM Roles for AWS Lambda Function that is an important topic under&hellip;","_links":{"self":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/71950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/comments?post=71950"}],"version-history":[{"count":4,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/71950\/revisions"}],"predecessor-version":[{"id":72218,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/71950\/revisions\/72218"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media\/71966"}],"wp:attachment":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media?parent=71950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/categories?post=71950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/tags?post=71950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}