filmov
tv
How To Read AWS S3 File Using Lambda Function (2 Min)
![preview_player](https://i.ytimg.com/vi/VZTYQRbh0Kg/maxresdefault.jpg)
Показать описание
In this tutorial, you'll learn how to read AWS S3 file using a lambda function.
—
—
Video Transcript:
—
Hi guys, this is Abi from Gokcedb. In this video, you’re going to learn how to read an AWS S3 file using a Lambda function. Let’s start by searching for S3 on AWS Console and then click on the first search result.
Next, click on Create Bucket and give it a name. I’m going to leave all the settings to default and then hit the create button. Now, go inside my AWS Bucket and click on the upload button.
Click on Create function and give it a name. For runtime, I’m going to select Python and for Default Execution Role, I’m going to select Create a New Role from AWS Policy Templates. Give the Role a name and from Policy Templates, search for Amazon S3 Object Read-Only Permission.
Hit the Create function button and scroll down to the Code Source Section. Here, I’m going to copy-paste my pre-written Python Code. On line 3, I’m importing border 3 which is the SDK library for AWS.
On line 4, I’m defining the S3 client. And lines 7 and 8, I’m defining the Bucket name and the File name. On line 10, I’m using the Get Underscore Object Method to get the response back from the S3 Client.
On line 13, I’m parsing the response body and reading the file data. Finally, on line 16, I’m returning the file data in all uppercase. Next, let’s copy and paste this code into the Lambda underscore function and hit deploy.
Click on test and give this Test Event a name. Save and hit test again to test your Lambda function. As expected, we got the hello world response pack in all caps.
Next, click on configuration and choose the function URL. Click an authentication type. I’m going to select none and hit save.
Now you should see a function URL assigned to your Lambda function which you can access through any browser. There you have it. Make sure you like, subscribe, and turn on the notification bell. Until next time.
import json
import boto3
def lambda_handler(event, context):
bucket_name = 'myawsbucket1098'
print("s3_response:", s3_response)
file_data = s3_response["Body"].read().decode('utf')
print("file_data:", file_data)
return str(file_data).upper()
—
—
Video Transcript:
—
Hi guys, this is Abi from Gokcedb. In this video, you’re going to learn how to read an AWS S3 file using a Lambda function. Let’s start by searching for S3 on AWS Console and then click on the first search result.
Next, click on Create Bucket and give it a name. I’m going to leave all the settings to default and then hit the create button. Now, go inside my AWS Bucket and click on the upload button.
Click on Create function and give it a name. For runtime, I’m going to select Python and for Default Execution Role, I’m going to select Create a New Role from AWS Policy Templates. Give the Role a name and from Policy Templates, search for Amazon S3 Object Read-Only Permission.
Hit the Create function button and scroll down to the Code Source Section. Here, I’m going to copy-paste my pre-written Python Code. On line 3, I’m importing border 3 which is the SDK library for AWS.
On line 4, I’m defining the S3 client. And lines 7 and 8, I’m defining the Bucket name and the File name. On line 10, I’m using the Get Underscore Object Method to get the response back from the S3 Client.
On line 13, I’m parsing the response body and reading the file data. Finally, on line 16, I’m returning the file data in all uppercase. Next, let’s copy and paste this code into the Lambda underscore function and hit deploy.
Click on test and give this Test Event a name. Save and hit test again to test your Lambda function. As expected, we got the hello world response pack in all caps.
Next, click on configuration and choose the function URL. Click an authentication type. I’m going to select none and hit save.
Now you should see a function URL assigned to your Lambda function which you can access through any browser. There you have it. Make sure you like, subscribe, and turn on the notification bell. Until next time.
import json
import boto3
def lambda_handler(event, context):
bucket_name = 'myawsbucket1098'
print("s3_response:", s3_response)
file_data = s3_response["Body"].read().decode('utf')
print("file_data:", file_data)
return str(file_data).upper()
Комментарии