это код, который я использовал:
import json
import urllib.request
import boto3
import os
from datetime import datetime
def lambda_handler(event, context):
# Define the SingStat API
endpointapi_url = "https://tablebuilder.singstat.gov.sg/ap ... ta/M651351"
try:
# Make an HTTP request to the API
with urllib.request.urlopen(api_url) as response:
data = json.loads(response.read().decode())
# Process the data as needed
json_data = json.dumps(data)
# Generate a unique filename using the current timestamp
timestamp = datetime.utcnow().strftime('%Y-%m-%dT%H-%M-%SZ')
key = f'daec-project/singstat_data_{timestamp}.json'
# Upload the data to an S3 bucket
bucket_name = "daec-project"
s3 = boto3.client("s3")
s3.put_object(Bucket=bucket_name, Key=key, Body=json_data, ContentType='application/json')
return {
'statusCode': 200,
'body': json.dumps('Data uploaded to S3 successfully!')
}
except urllib.error.HTTPError as e:
return {
'statusCode': e.code,
'body': json.dumps(f'HTTP Error: {e.reason}')
}
except Exception as e:
return {
'statusCode': 500,
'body': json.dumps(f'Error: {str(e)}')
}
Но AWS Lambda продолжает выдавать мне эту ошибку:
Test Event Namedaec-proj
Response{"statusCode": 403,"body": ""HTTP Error: Forbidden""}
Function LogsSTART RequestId: 999af3a7-b3d7-4400-940f-a2114e3fccbe Version: $LATESTEND RequestId: 999af3a7-b3d7-4400-940f-a2114e3fccbeREPORT RequestId: 999af3a7-b3d7-4400-940f-a2114e3fccbe Duration: 1924.69 ms Billed Duration: 1925 ms Memory Size: 128 MB Max Memory Used: 65 MB Init Duration: 285.07 ms
Request ID999af3a7-b3d7-4400-940f-a2114e3fccbe
Подробнее здесь: https://stackoverflow.com/questions/787 ... aws-lambda