示例代码:
import boto3
from boto3_type_annotations.opensearch import Client as OpenSearchClient
s3 = boto3.client('s3')
opensearch = boto3.client('opensearch') # type: OpenSearchClient
bucket_name = 'example-bucket'
object_key = 'example-file.pdf'
# Read file from S3
response = s3.get_object(Bucket=bucket_name, Key=object_key)
file_content = response['Body'].read()
# Send file to OpenSearch cluster
response = opensearch.index(
index='my_index',
body={
'attachment': file_content
}
)