# Allow Public Read access to an S3 Bucket
To allow public read access to an S3 bucket:
Open the AWS S3 console and click on the bucket’s name
Click on the Permissions tab
Find the Block public access (bucket settings) section, click on the Edit button, uncheck the checkboxes and click on Save changes
In the Permissions tab, scroll down to the Bucket policy section and click on the Edit button. Paste the following policy into the textarea to grant public read access to all files in your S3 bucket.
Replace the YOUR_BUCKET_NAME placeholder with your bucket’s name.
bucket-policy-public-read
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
}
]
}
For example, the bucket policy of an S3 bucket with the name my-bucket will look like:
Save the changes you’ve made to the bucket’s [...x]
policy and your bucket will have public read access enabled.
(Optional) – If you need to access your bucket with HTTP requests from the browser, you have to update the bucket’s Cross-origin resource sharing (CORS) options to allow your frontend’s requests
In the Permissions tab of your S3 bucket, scroll down to the Cross-origin resource sharing (CORS) section and click on the Edit button
Paste the following JSON into the textarea and save the changes
To test that your bucket has public read access enabled:
Click on the Objects tab in your S3 bucket.
Click on the checkbox next to a file’s name.
Click on the Copy URL button at the top and copy the public URL of the file.
Paste the URL in your browser and you should see the contents of the file (for HTML files or images).
Note that you’ll see a red badge with the text Publicly accessible next to your bucket’s name.
In this case, the bucket policy only grants public read access to the bucket, so other people can’t add objects to your S3 bucket.
Either you can take query string inside Lambda like below,
var result = event["queryStringParameters"]['queryStringParam1']
According to your API URL,
var postcode = event["queryStringParameters"]['postcode']
var house = event["queryStringParameters"]['house']
or you can use body mapping template in the integration request section and get request body and query strings. Construct a new JSON at body mapping template, which will have data from request body and query string. As we are adding body mapping template your business logic will get the JSON we have constructed at body mapping template.
Inside body mapping template to get query string please do ,
You can learn more about the related topics by checking out the following tutorials:
List all Files in an S3 Bucket with AWS CLI
Get the Size of a Folder in AWS S3 Bucket
How to Get the Size of an AWS S3 Bucket
Configure CORS for an AWS S3 Bucket
Copy a Local Folder to an S3 Bucket
Download a Folder from AWS S3
How to Rename a Folder in AWS S3
Copy Files and Folders between S3 Buckets
How to Delete a Folder from an S3 Bucket
Count Number of Objects in S3 Bucket
Download an Entire S3 Bucket – Complete Guide
AWS CDK Tutorial for Beginners – Step-by-Step Guide
How to use Parameters in AWS CDK
The Bucket you are attempting to Access AWS S3 Error [Fixed]
How to Exclude multiple Folders with AWS S3 Sync
import requests
import json
import time
def lambda_handler(event, context):
# TODO implement
url = ""
print(event, context)
httpMethod = event.get('httpMethod')
path = event.get('path')
if httpMethod == "GET" and path == "/Wh2":
params = event.get('queryStringParameters')
if params is None:
print(params, 86666666666666)
text = ("Hello there! My name is ' joi ', your English coach."
"I'm really happy to start this journey with you. Let's get started by telling me your name and where you're from."
"I'd love to learn more about you! And if you ever feel confused or need help, don't hesitate to ask me.")
else:
text = params["text"]
print(text)
#try:
#text = event["queryStringParameters"]["text"]
#except KeyError as e:
#text = ("Hello there! My name is ' joi ', your English coach."
#"I'm really happy to start this journey with you. Let's get started by telling me your name and where you're from."
#"I'd love to learn more about you! And if you ever feel confused or need help, don't hesitate to ask me.")
payload = json.dumps({
"voice": "en-US-DavisNeural",
"content": [text],
"title": "Testing public api convertion"
})
headers = {
#'Authorization': 'f592b758e0ee4094a4fad34be3371663',
'Authorization': '86b294b3b5474335ab5e2a49f7b956c9',
#'X-User-ID': 'zoSFLZ0CUsajZj4NliirGr1qgt73',
'X-User-ID': '8biOMUQv0IXAxYRdj1TQJmYUmwD3',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
data = json.loads(response.text)
print(data['transcriptionId'])
time.sleep(2)
url = ''+data['transcriptionId']
x = requests.get(url, headers=headers)
data = json.loads(x.text)
print(data['audioUrl'])
return {
'statusCode': 200,
'body': json.dumps(data['audioUrl'])
}