{
"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 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
Permissionstab of your S3 bucket, scroll down to theCross-origin resource sharing (CORS)section and click on theEditbutton - Paste the following JSON into the textarea and save the changes
- In the
cors-configuration
[
{
"AllowedHeaders": [
"Authorization",
"Content-Length"
],
"AllowedMethods": [
"GET"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 3000
}
]
To test that your bucket has public read access enabled:
- Click on the
Objectstab in your S3 bucket. - Click on the checkbox next to a file’s name.
- Click on the
Copy URLbutton 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. https://bobbyhadz.com/blog/aws-s3-allow-public-read-access
https://stackoverflow.com/questions/47134556/python-pass-querystring-parameters-to-api-gateway
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 ,
$input.params(‘querystringkey’)
For example inside body mapping template,
#set($inputRoot = $input.path('$'))
{
"firstName" : "$input.path('$.firstName')",
"lastName" : "$input.path('$.lastName')"
"language" : "$input.params('$.language')"
}
Run code snippet
Please read https://aws.amazon.com/blogs/compute/tag/mapping-templates/ for more details on body mapping template
# Additional Resources
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 = "https://play.ht/api/v1/convert"
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 = 'https://play.ht/api/v1/articleStatus?transcriptionId='+data['transcriptionId']
x = requests.get(url, headers=headers)
data = json.loads(x.text)
print(data['audioUrl'])
return {
'statusCode': 200,
'body': json.dumps(data['audioUrl'])
}
Sharing is caringFacebookX / TwitterLinkedInWhatsAppTelegramRedditEmail965 words · 178 views