I am working on a Lambda function that processes incoming audio files and uploads the resulting audio file to S3.
I am receiving the following error:
"errorMessage": "SSL validation failed for https://[mybucket].s3.amazonaws.com/[mypath]/[myfile].mp3 EOF occurred in violation of protocol (_ssl.c:2427)",
"errorType": "SSLError",
I have tried uploading both a file from memory and uploading a file from a path in /tmp storage.
Same error in both cases.
I have granted the Lambda function S3 access
The Lambda function and S3 bucket are in the same account and region
I have used the same Execution Role with another Lambda function to write to this S3 bucket before without error
Here is my code:
import json
import boto3
from pydub import AudioSegment
from io import BytesIO
import datetime
s3_client = boto3.client('s3')
def load_audio_from_s3(bucket, key):
obj = s3_client.get_object(Bucket=bucket, Key=key)
return AudioSegment.from_file(BytesIO(obj['Body'].read()), format='mp3')
def upload_fileobj_to_s3(file_obj, bucket, object_name):
file_obj.seek(0) # Reset file pointer to the start
s3_client.upload_fileobj(file_obj, bucket, object_name, ExtraArgs={'ACL': 'public-read'})
def lambda_handler(event, context):
# Extracting information from the event object
voice_file_keys = event['voice_file_keys']
# .... process audio ...
# .... process audio ...
# .... process audio ...
# Save the final product to an in-memory file
output_buffer = BytesIO()
datetime_str = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
output_filename = f"{datetime_str}.mp3"
final_product.export(output_buffer, format='mp3', parameters=["-codec:a", "libmp3lame"])
# Upload the in-memory file to S3
s3_object_name = f"final_audio/{output_filename}"
upload_fileobj_to_s3(output_buffer, s3_bucket_name, s3_object_name)
return {
'statusCode': 200,
'body': json.dumps(Audio {output_filename} processing and upload completed successfully.')
}
This worked - thanks!
I was previously relying on the version of boto3 that was available in the Lambda environment (which was not the latest release).
I added the latest release of boto3 to my Lambda layer, and that solved the SLL verification issue.