select_object_content
(**kwargs)¶This action filters the contents of an Amazon S3 object based on a simple structured query language (SQL) statement. In the request, along with the SQL expression, you must also specify a data serialization format (JSON, CSV, or Apache Parquet) of the object. Amazon S3 uses this format to parse object data into records, and returns only records that match the specified SQL expression. You must also specify the data serialization format for the response.
This action is not supported by Amazon S3 on Outposts.
For more information about Amazon S3 Select, see Selecting Content from Objects and SELECT Command in the Amazon S3 User Guide .
For more information about using SQL with Amazon S3 Select, see SQL Reference for Amazon S3 Select and S3 Glacier Select in the Amazon S3 User Guide .
Permissions
You must have s3:GetObject
permission for this operation. Amazon S3 Select does not support anonymous access. For more information about permissions, see Specifying Permissions in a Policy in the Amazon S3 User Guide .
Object Data Formats
You can use Amazon S3 Select to query objects that have the following format properties:
Working with the Response Body
Given the response size is unknown, Amazon S3 Select streams the response as a series of messages and includes a Transfer-Encoding
header with chunked
as its value in the response. For more information, see Appendix: SelectObjectContent Response.
GetObject Support
The SelectObjectContent
action does not support the following GetObject
functionality. For more information, see GetObject.
Range
: Although you can specify a scan range for an Amazon S3 Select request (see SelectObjectContentRequest - ScanRange in the request parameters), you cannot specify the range of bytes of an object to return.REDUCED_REDUNDANCY
storage classes. For more information, about storage classes see Storage Classes in the Amazon S3 User Guide .Special Errors
For a list of special errors for this operation, see List of SELECT Object Content Error Codes
Related Resources
See also: AWS API Documentation
Request Syntax
response = client.select_object_content(
Bucket='string',
Key='string',
SSECustomerAlgorithm='string',
SSECustomerKey='string',
Expression='string',
ExpressionType='SQL',
RequestProgress={
'Enabled': True|False
},
InputSerialization={
'CSV': {
'FileHeaderInfo': 'USE'|'IGNORE'|'NONE',
'Comments': 'string',
'QuoteEscapeCharacter': 'string',
'RecordDelimiter': 'string',
'FieldDelimiter': 'string',
'QuoteCharacter': 'string',
'AllowQuotedRecordDelimiter': True|False
},
'CompressionType': 'NONE'|'GZIP'|'BZIP2',
'JSON': {
'Type': 'DOCUMENT'|'LINES'
},
'Parquet': {}
},
OutputSerialization={
'CSV': {
'QuoteFields': 'ALWAYS'|'ASNEEDED',
'QuoteEscapeCharacter': 'string',
'RecordDelimiter': 'string',
'FieldDelimiter': 'string',
'QuoteCharacter': 'string'
},
'JSON': {
'RecordDelimiter': 'string'
}
},
ScanRange={
'Start': 123,
'End': 123
},
ExpectedBucketOwner='string'
)
[REQUIRED]
The S3 bucket.
[REQUIRED]
The object key.
The MD5 server-side encryption (SSE) customer managed key. This parameter is needed only when the object was created using a checksum algorithm. For more information, see Protecting data using SSE-C keys in the Amazon S3 User Guide .
Please note that this parameter is automatically populated if it is not provided. Including this parameter is not required
[REQUIRED]
The expression that is used to query the object.
[REQUIRED]
The type of the provided expression (for example, SQL).
Specifies if periodic request progress information should be enabled.
Specifies whether periodic QueryProgress frames should be sent. Valid values: TRUE, FALSE. Default value: FALSE.
[REQUIRED]
Describes the format of the data in the object that is being queried.
Describes the serialization of a CSV-encoded object.
Describes the first line of input. Valid values are:
NONE
: First line is not a header.IGNORE
: First line is a header, but you can't use the header values to indicate the column in an expression. You can use column position (such as _1, _2, …) to indicate the column ( SELECT s._1 FROM OBJECT s
).Use
: First line is a header, and you can use the header value to identify a column in an expression ( SELECT "name" FROM OBJECT
).A single character used to indicate that a row should be ignored when the character is present at the start of that row. You can specify any character to indicate a comment line.
A single character used for escaping the quotation mark character inside an already escaped value. For example, the value """ a , b """
is parsed as " a , b "
.
A single character used to separate individual records in the input. Instead of the default value, you can specify an arbitrary delimiter.
A single character used to separate individual fields in a record. You can specify an arbitrary delimiter.
A single character used for escaping when the field delimiter is part of the value. For example, if the value is a, b
, Amazon S3 wraps this field value in quotation marks, as follows: " a , b "
.
Type: String
Default: "
Ancestors: CSV
Specifies that CSV field values may contain quoted record delimiters and such records should be allowed. Default value is FALSE. Setting this value to TRUE may lower performance.
Specifies object's compression format. Valid values: NONE, GZIP, BZIP2. Default Value: NONE.
Specifies JSON as object's input serialization format.
The type of JSON. Valid values: Document, Lines.
Specifies Parquet as object's input serialization format.
[REQUIRED]
Describes the format of the data that you want Amazon S3 to return in response.
Describes the serialization of CSV-encoded Select results.
Indicates whether to use quotation marks around output fields.
ALWAYS
: Always use quotation marks for output fields.ASNEEDED
: Use quotation marks for output fields when needed.The single character used for escaping the quote character inside an already escaped value.
A single character used to separate individual records in the output. Instead of the default value, you can specify an arbitrary delimiter.
The value used to separate individual fields in a record. You can specify an arbitrary delimiter.
A single character used for escaping when the field delimiter is part of the value. For example, if the value is a, b
, Amazon S3 wraps this field value in quotation marks, as follows: " a , b "
.
Specifies JSON as request's output serialization format.
The value used to separate individual records in the output. If no value is specified, Amazon S3 uses a newline character ('n').
Specifies the byte range of the object to get the records from. A record is processed when its first byte is contained by the range. This parameter is optional, but when specified, it must not be empty. See RFC 2616, Section 14.35.1 about how to specify the start and end of the range.
ScanRange
may be used in the following ways:
<scanrange><start>50</start><end>100</end></scanrange>
- process only the records starting between the bytes 50 and 100 (inclusive, counting from zero)<scanrange><start>50</start></scanrange>
- process only the records starting after the byte 50<scanrange><end>50</end></scanrange>
- process only the records within the last 50 bytes of the file.Specifies the start of the byte range. This parameter is optional. Valid values: non-negative integers. The default value is 0. If only start
is supplied, it means scan from that point to the end of the file. For example, <scanrange><start>50</start></scanrange>
means scan from byte 50 until the end of the file.
Specifies the end of the byte range. This parameter is optional. Valid values: non-negative integers. The default value is one less than the size of the object being queried. If only the End parameter is supplied, it is interpreted to mean scan the last N bytes of the file. For example, <scanrange><end>50</end></scanrange>
means scan the last 50 bytes.
403 Forbidden
(access denied).dict
The response of this operation contains an EventStream
member. When iterated the EventStream
will yield events based on the structure below, where only one of the top level keys will be present for any given event.
Response Syntax
{
'Payload': EventStream({
'Records': {
'Payload': b'bytes'
},
'Stats': {
'Details': {
'BytesScanned': 123,
'BytesProcessed': 123,
'BytesReturned': 123
}
},
'Progress': {
'Details': {
'BytesScanned': 123,
'BytesProcessed': 123,
'BytesReturned': 123
}
},
'Cont': {},
'End': {}
})
}
Response Structure
(dict) --
Payload (EventStream
) --
The array of results.
Records (dict) --
The Records Event.
Payload (bytes) --
The byte array of partial, one or more result records.
Stats (dict) --
The Stats Event.
Details (dict) --
The Stats event details.
BytesScanned (integer) --
The total number of object bytes scanned.
BytesProcessed (integer) --
The total number of uncompressed object bytes processed.
BytesReturned (integer) --
The total number of bytes of records payload data returned.
Progress (dict) --
The Progress Event.
Details (dict) --
The Progress event details.
BytesScanned (integer) --
The current number of object bytes scanned.
BytesProcessed (integer) --
The current number of uncompressed object bytes processed.
BytesReturned (integer) --
The current number of bytes of records payload data returned.
Cont (dict) --
The Continuation Event.
End (dict) --
The End Event.