AWS SDK 또는 CLI와 함께 Scan
사용
다음 코드 예제는 Scan
의 사용 방법을 보여 줍니다.
작업 예시는 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 다음 코드 예제에서는 컨텍스트 내에서 이 작업을 확인할 수 있습니다.
- .NET
-
- AWS SDK for .NET
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. public static async Task<int> ScanTableAsync( AmazonDynamoDBClient client, string tableName, int startYear, int endYear) { var request = new ScanRequest { TableName = tableName, ExpressionAttributeNames = new Dictionary<string, string> { { "#yr", "year" }, }, ExpressionAttributeValues = new Dictionary<string, AttributeValue> { { ":y_a", new AttributeValue { N = startYear.ToString() } }, { ":y_z", new AttributeValue { N = endYear.ToString() } }, }, FilterExpression = "#yr between :y_a and :y_z", ProjectionExpression = "#yr, title, info.actors[0], info.directors, info.running_time_secs", Limit = 10 // Set a limit to demonstrate using the LastEvaluatedKey. }; // Keep track of how many movies were found. int foundCount = 0; var response = new ScanResponse(); do { response = await client.ScanAsync(request); foundCount += response.Items.Count; response.Items.ForEach(i => DisplayItem(i)); request.ExclusiveStartKey = response.LastEvaluatedKey; } while (response.LastEvaluatedKey.Count > 0); return foundCount; }
-
API 세부 정보는 AWS SDK for .NET API 참조의 Scan을 참조하십시오.
-
- Bash
-
- Bash 스크립트와 함께 AWS CLI사용
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. ############################################################################# # function dynamodb_scan # # This function scans a DynamoDB table. # # Parameters: # -n table_name -- The name of the table. # -f filter_expression -- The filter expression. # -a expression_attribute_names -- Path to JSON file containing the expression attribute names. # -v expression_attribute_values -- Path to JSON file containing the expression attribute values. # [-p projection_expression] -- Optional projection expression. # # Returns: # The items as json output. # And: # 0 - If successful. # 1 - If it fails. ########################################################################### function dynamodb_scan() { local table_name filter_expression expression_attribute_names expression_attribute_values projection_expression response local option OPTARG # Required to use getopts command in a function. # ###################################### # Function usage explanation ####################################### function usage() { echo "function dynamodb_scan" echo "Scan a DynamoDB table." echo " -n table_name -- The name of the table." echo " -f filter_expression -- The filter expression." echo " -a expression_attribute_names -- Path to JSON file containing the expression attribute names." echo " -v expression_attribute_values -- Path to JSON file containing the expression attribute values." echo " [-p projection_expression] -- Optional projection expression." echo "" } while getopts "n:f:a:v:p:h" option; do case "${option}" in n) table_name="${OPTARG}" ;; f) filter_expression="${OPTARG}" ;; a) expression_attribute_names="${OPTARG}" ;; v) expression_attribute_values="${OPTARG}" ;; p) projection_expression="${OPTARG}" ;; h) usage return 0 ;; \?) echo "Invalid parameter" usage return 1 ;; esac done export OPTIND=1 if [[ -z "$table_name" ]]; then errecho "ERROR: You must provide a table name with the -n parameter." usage return 1 fi if [[ -z "$filter_expression" ]]; then errecho "ERROR: You must provide a filter expression with the -f parameter." usage return 1 fi if [[ -z "$expression_attribute_names" ]]; then errecho "ERROR: You must provide expression attribute names with the -a parameter." usage return 1 fi if [[ -z "$expression_attribute_values" ]]; then errecho "ERROR: You must provide expression attribute values with the -v parameter." usage return 1 fi if [[ -z "$projection_expression" ]]; then response=$(aws dynamodb scan \ --table-name "$table_name" \ --filter-expression "$filter_expression" \ --expression-attribute-names file://"$expression_attribute_names" \ --expression-attribute-values file://"$expression_attribute_values") else response=$(aws dynamodb scan \ --table-name "$table_name" \ --filter-expression "$filter_expression" \ --expression-attribute-names file://"$expression_attribute_names" \ --expression-attribute-values file://"$expression_attribute_values" \ --projection-expression "$projection_expression") fi local error_code=${?} if [[ $error_code -ne 0 ]]; then aws_cli_error_log $error_code errecho "ERROR: AWS reports scan operation failed.$response" return 1 fi echo "$response" return 0 }
이 예제에 사용된 유틸리티 함수
############################################################################### # function errecho # # This function outputs everything sent to it to STDERR (standard error output). ############################################################################### function errecho() { printf "%s\n" "$*" 1>&2 } ############################################################################## # function aws_cli_error_log() # # This function is used to log the error messages from the AWS CLI. # # See https://docs.aws.amazon.com/cli/latest/topic/return-codes.html#cli-aws-help-return-codes. # # The function expects the following argument: # $1 - The error code returned by the AWS CLI. # # Returns: # 0: - Success. # ############################################################################## function aws_cli_error_log() { local err_code=$1 errecho "Error code : $err_code" if [ "$err_code" == 1 ]; then errecho " One or more S3 transfers failed." elif [ "$err_code" == 2 ]; then errecho " Command line failed to parse." elif [ "$err_code" == 130 ]; then errecho " Process received SIGINT." elif [ "$err_code" == 252 ]; then errecho " Command syntax invalid." elif [ "$err_code" == 253 ]; then errecho " The system environment or configuration was invalid." elif [ "$err_code" == 254 ]; then errecho " The service returned an error." elif [ "$err_code" == 255 ]; then errecho " 255 is a catch-all error." fi return 0 }
-
API 세부 정보는 AWS CLI 명령 참조의 Scan을 참조하십시오.
-
- C++
-
- SDK for C++
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. //! Scan an Amazon DynamoDB table. /*! \sa scanTable() \param tableName: Name for the DynamoDB table. \param projectionExpression: An optional projection expression, ignored if empty. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::DynamoDB::scanTable(const Aws::String &tableName, const Aws::String &projectionExpression, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::DynamoDB::DynamoDBClient dynamoClient(clientConfiguration); Aws::DynamoDB::Model::ScanRequest request; request.SetTableName(tableName); if (!projectionExpression.empty()) request.SetProjectionExpression(projectionExpression); Aws::Vector<Aws::Map<Aws::String, Aws::DynamoDB::Model::AttributeValue>> all_items; Aws::Map<Aws::String, Aws::DynamoDB::Model::AttributeValue> last_evaluated_key; // Used for pagination; do { if (!last_evaluated_key.empty()) { request.SetExclusiveStartKey(last_evaluated_key); } const Aws::DynamoDB::Model::ScanOutcome &outcome = dynamoClient.Scan(request); if (outcome.IsSuccess()) { // Reference the retrieved items. const Aws::Vector<Aws::Map<Aws::String, Aws::DynamoDB::Model::AttributeValue>> &items = outcome.GetResult().GetItems(); all_items.insert(all_items.end(), items.begin(), items.end()); last_evaluated_key = outcome.GetResult().GetLastEvaluatedKey(); } else { std::cerr << "Failed to Scan items: " << outcome.GetError().GetMessage() << std::endl; return false; } } while (!last_evaluated_key.empty()); if (!all_items.empty()) { std::cout << "Number of items retrieved from scan: " << all_items.size() << std::endl; // Iterate each item and print. for (const Aws::Map<Aws::String, Aws::DynamoDB::Model::AttributeValue> &itemMap: all_items) { std::cout << "******************************************************" << std::endl; // Output each retrieved field and its value. for (const auto &itemEntry: itemMap) std::cout << itemEntry.first << ": " << itemEntry.second.GetS() << std::endl; } } else { std::cout << "No items found in table: " << tableName << std::endl; } return true; }
-
API 세부 정보는 AWS SDK for C++ API 참조의 Scan을 참조하십시오.
-
- CLI
-
- AWS CLI
-
테이블을 스캔하는 방법
다음
scan
예시에서는MusicCollection
테이블 전체를 스캔한 다음 'No One You Know' 아티스트의 곡으로 결과 범위를 좁힙니다. 각 항목에 대해 앨범 제목과 노래 제목만 반환됩니다.aws dynamodb scan \ --table-name
MusicCollection
\ --filter-expression"Artist = :a"
\ --projection-expression"#ST, #AT"
\ --expression-attribute-namesfile://expression-attribute-names.json
\ --expression-attribute-valuesfile://expression-attribute-values.json
expression-attribute-names.json
의 콘텐츠:{ "#ST": "SongTitle", "#AT":"AlbumTitle" }
expression-attribute-values.json
의 콘텐츠:{ ":a": {"S": "No One You Know"} }
출력:
{ "Count": 2, "Items": [ { "SongTitle": { "S": "Call Me Today" }, "AlbumTitle": { "S": "Somewhat Famous" } }, { "SongTitle": { "S": "Scared of My Shadow" }, "AlbumTitle": { "S": "Blue Sky Blues" } } ], "ScannedCount": 3, "ConsumedCapacity": null }
자세한 내용은 Amazon DynamoDB 개발자 안내서의 DynamoDB에서 스캔 작업을 참조하세요.
-
API 세부 정보는 AWS CLI 명령 참조의 Scan
을 참조하십시오.
-
- Go
-
- SDK for Go V2
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. // TableBasics encapsulates the Amazon DynamoDB service actions used in the examples. // It contains a DynamoDB service client that is used to act on the specified table. type TableBasics struct { DynamoDbClient *dynamodb.Client TableName string } // Scan gets all movies in the DynamoDB table that were released in a range of years // and projects them to return a reduced set of fields. // The function uses the `expression` package to build the filter and projection // expressions. func (basics TableBasics) Scan(ctx context.Context, startYear int, endYear int) ([]Movie, error) { var movies []Movie var err error var response *dynamodb.ScanOutput filtEx := expression.Name("year").Between(expression.Value(startYear), expression.Value(endYear)) projEx := expression.NamesList( expression.Name("year"), expression.Name("title"), expression.Name("info.rating")) expr, err := expression.NewBuilder().WithFilter(filtEx).WithProjection(projEx).Build() if err != nil { log.Printf("Couldn't build expressions for scan. Here's why: %v\n", err) } else { scanPaginator := dynamodb.NewScanPaginator(basics.DynamoDbClient, &dynamodb.ScanInput{ TableName: aws.String(basics.TableName), ExpressionAttributeNames: expr.Names(), ExpressionAttributeValues: expr.Values(), FilterExpression: expr.Filter(), ProjectionExpression: expr.Projection(), }) for scanPaginator.HasMorePages() { response, err = scanPaginator.NextPage(ctx) if err != nil { log.Printf("Couldn't scan for movies released between %v and %v. Here's why: %v\n", startYear, endYear, err) break } else { var moviePage []Movie err = attributevalue.UnmarshalListOfMaps(response.Items, &moviePage) if err != nil { log.Printf("Couldn't unmarshal query response. Here's why: %v\n", err) break } else { movies = append(movies, moviePage...) } } } } return movies, err } // Movie encapsulates data about a movie. Title and Year are the composite primary key // of the movie in Amazon DynamoDB. Title is the sort key, Year is the partition key, // and Info is additional data. type Movie struct { Title string `dynamodbav:"title"` Year int `dynamodbav:"year"` Info map[string]interface{} `dynamodbav:"info"` } // GetKey returns the composite primary key of the movie in a format that can be // sent to DynamoDB. func (movie Movie) GetKey() map[string]types.AttributeValue { title, err := attributevalue.Marshal(movie.Title) if err != nil { panic(err) } year, err := attributevalue.Marshal(movie.Year) if err != nil { panic(err) } return map[string]types.AttributeValue{"title": title, "year": year} } // String returns the title, year, rating, and plot of a movie, formatted for the example. func (movie Movie) String() string { return fmt.Sprintf("%v\n\tReleased: %v\n\tRating: %v\n\tPlot: %v\n", movie.Title, movie.Year, movie.Info["rating"], movie.Info["plot"]) }
-
API 세부 정보는 AWS SDK for Go API 참조의 Scan
을 참조하십시오.
-
- Java
-
- SDK for Java 2.x
-
참고
GitHub에 더 많은 내용이 있습니다. AWS코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. DynamoDbClient를 사용하여 Amazon DynamoDB 테이블을 스캔합니다.
import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.DynamoDbException; import software.amazon.awssdk.services.dynamodb.model.ScanRequest; import software.amazon.awssdk.services.dynamodb.model.ScanResponse; import java.util.Map; import java.util.Set; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html * * To scan items from an Amazon DynamoDB table using the AWS SDK for Java V2, * its better practice to use the * Enhanced Client, See the EnhancedScanRecords example. */ public class DynamoDBScanItems { public static void main(String[] args) { final String usage = """ Usage: <tableName> Where: tableName - The Amazon DynamoDB table to get information from (for example, Music3). """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String tableName = args[0]; Region region = Region.US_EAST_1; DynamoDbClient ddb = DynamoDbClient.builder() .region(region) .build(); scanItems(ddb, tableName); ddb.close(); } public static void scanItems(DynamoDbClient ddb, String tableName) { try { ScanRequest scanRequest = ScanRequest.builder() .tableName(tableName) .build(); ScanResponse response = ddb.scan(scanRequest); for (Map<String, AttributeValue> item : response.items()) { Set<String> keys = item.keySet(); for (String key : keys) { System.out.println("The key name is " + key + "\n"); System.out.println("The value is " + item.get(key).s()); } } } catch (DynamoDbException e) { e.printStackTrace(); System.exit(1); } } }
-
API 세부 정보는 AWS SDK for Java 2.x API 참조의 Scan을 참조하십시오.
-
- JavaScript
-
- SDK for JavaScript (v3)
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. 이 예제에서는 문서 클라이언트를 사용하여 DynamoDB의 항목 작업을 단순화합니다. API에 대한 세부 정보는 ScanCommand를 참조하십시오.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, ScanCommand } from "@aws-sdk/lib-dynamodb"; const client = new DynamoDBClient({}); const docClient = DynamoDBDocumentClient.from(client); export const main = async () => { const command = new ScanCommand({ ProjectionExpression: "#Name, Color, AvgLifeSpan", ExpressionAttributeNames: { "#Name": "Name" }, TableName: "Birds", }); const response = await docClient.send(command); for (const bird of response.Items) { console.log(`${bird.Name} - (${bird.Color}, ${bird.AvgLifeSpan})`); } return response; };
-
API 세부 정보는 AWS SDK for JavaScript API 참조의 Scan을 참조하십시오.
-
- SDK for JavaScript (v2)
-
참고
GitHub에 더 많은 내용이 있습니다. AWS코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. // Load the AWS SDK for Node.js. var AWS = require("aws-sdk"); // Set the AWS Region. AWS.config.update({ region: "REGION" }); // Create DynamoDB service object. var ddb = new AWS.DynamoDB({ apiVersion: "2012-08-10" }); const params = { // Specify which items in the results are returned. FilterExpression: "Subtitle = :topic AND Season = :s AND Episode = :e", // Define the expression attribute value, which are substitutes for the values you want to compare. ExpressionAttributeValues: { ":topic": { S: "SubTitle2" }, ":s": { N: 1 }, ":e": { N: 2 }, }, // Set the projection expression, which are the attributes that you want. ProjectionExpression: "Season, Episode, Title, Subtitle", TableName: "EPISODES_TABLE", }; ddb.scan(params, function (err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); data.Items.forEach(function (element, index, array) { console.log( "printing", element.Title.S + " (" + element.Subtitle.S + ")" ); }); } });
-
자세한 정보는 AWS SDK for JavaScript 개발자 안내서를 참조하십시오.
-
API 세부 정보는 AWS SDK for JavaScript API 참조의 Scan을 참조하십시오.
-
- Kotlin
-
- SDK for Kotlin
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. suspend fun scanItems(tableNameVal: String) { val request = ScanRequest { tableName = tableNameVal } DynamoDbClient { region = "us-east-1" }.use { ddb -> val response = ddb.scan(request) response.items?.forEach { item -> item.keys.forEach { key -> println("The key name is $key\n") println("The value is ${item[key]}") } } } }
-
API 세부 정보는 AWS SDK for Kotlin API 참조의 Scan
를 참조하십시오.
-
- PHP
-
- SDK for PHP
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. $yearsKey = [ 'Key' => [ 'year' => [ 'N' => [ 'minRange' => 1990, 'maxRange' => 1999, ], ], ], ]; $filter = "year between 1990 and 1999"; echo "\nHere's a list of all the movies released in the 90s:\n"; $result = $service->scan($tableName, $yearsKey, $filter); foreach ($result['Items'] as $movie) { $movie = $marshal->unmarshalItem($movie); echo $movie['title'] . "\n"; } public function scan(string $tableName, array $key, string $filters) { $query = [ 'ExpressionAttributeNames' => ['#year' => 'year'], 'ExpressionAttributeValues' => [ ":min" => ['N' => '1990'], ":max" => ['N' => '1999'], ], 'FilterExpression' => "#year between :min and :max", 'TableName' => $tableName, ]; return $this->dynamoDbClient->scan($query); }
-
API 세부 정보는 AWS SDK for PHP API 참조의 Scan을 참조하십시오.
-
- PowerShell
-
- PowerShell용 도구
-
예 1: Music 테이블에서 모든 항목을 반환합니다.
Invoke-DDBScan -TableName 'Music' | ConvertFrom-DDBItem
출력:
Name Value ---- ----- Genre Country Artist No One You Know Price 1.94 CriticRating 9 SongTitle Somewhere Down The Road AlbumTitle Somewhat Famous Genre Country Artist No One You Know Price 1.98 CriticRating 8.4 SongTitle My Dog Spot AlbumTitle Hey Now
예 2: Music 테이블에서 CriticRating이 9 이상인 항목을 반환합니다.
$scanFilter = @{ CriticRating = [Amazon.DynamoDBv2.Model.Condition]@{ AttributeValueList = @(@{N = '9'}) ComparisonOperator = 'GE' } } Invoke-DDBScan -TableName 'Music' -ScanFilter $scanFilter | ConvertFrom-DDBItem
출력:
Name Value ---- ----- Genre Country Artist No One You Know Price 1.94 CriticRating 9 SongTitle Somewhere Down The Road AlbumTitle Somewhat Famous
-
API 세부 정보는 AWS Tools for PowerShell Cmdlet 참조의 Scan을 참조하세요.
-
- Python
-
- SDK for Python (Boto3)
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. class Movies: """Encapsulates an Amazon DynamoDB table of movie data. Example data structure for a movie record in this table: { "year": 1999, "title": "For Love of the Game", "info": { "directors": ["Sam Raimi"], "release_date": "1999-09-15T00:00:00Z", "rating": 6.3, "plot": "A washed up pitcher flashes through his career.", "rank": 4987, "running_time_secs": 8220, "actors": [ "Kevin Costner", "Kelly Preston", "John C. Reilly" ] } } """ def __init__(self, dyn_resource): """ :param dyn_resource: A Boto3 DynamoDB resource. """ self.dyn_resource = dyn_resource # The table variable is set during the scenario in the call to # 'exists' if the table exists. Otherwise, it is set by 'create_table'. self.table = None def scan_movies(self, year_range): """ Scans for movies that were released in a range of years. Uses a projection expression to return a subset of data for each movie. :param year_range: The range of years to retrieve. :return: The list of movies released in the specified years. """ movies = [] scan_kwargs = { "FilterExpression": Key("year").between( year_range["first"], year_range["second"] ), "ProjectionExpression": "#yr, title, info.rating", "ExpressionAttributeNames": {"#yr": "year"}, } try: done = False start_key = None while not done: if start_key: scan_kwargs["ExclusiveStartKey"] = start_key response = self.table.scan(**scan_kwargs) movies.extend(response.get("Items", [])) start_key = response.get("LastEvaluatedKey", None) done = start_key is None except ClientError as err: logger.error( "Couldn't scan for movies. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise return movies
-
API 세부 정보는 AWSSDK for Python (Boto3) API 참조의 Scan를 참조하십시오.
-
- Ruby
-
- SDK for Ruby
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. class DynamoDBBasics attr_reader :dynamo_resource, :table def initialize(table_name) client = Aws::DynamoDB::Client.new(region: 'us-east-1') @dynamo_resource = Aws::DynamoDB::Resource.new(client: client) @table = @dynamo_resource.table(table_name) end # Scans for movies that were released in a range of years. # Uses a projection expression to return a subset of data for each movie. # # @param year_range [Hash] The range of years to retrieve. # @return [Array] The list of movies released in the specified years. def scan_items(year_range) movies = [] scan_hash = { filter_expression: '#yr between :start_yr and :end_yr', projection_expression: '#yr, title, info.rating', expression_attribute_names: { '#yr' => 'year' }, expression_attribute_values: { ':start_yr' => year_range[:start], ':end_yr' => year_range[:end] } } done = false start_key = nil until done scan_hash[:exclusive_start_key] = start_key unless start_key.nil? response = @table.scan(scan_hash) movies.concat(response.items) unless response.items.empty? start_key = response.last_evaluated_key done = start_key.nil? end rescue Aws::DynamoDB::Errors::ServiceError => e puts("Couldn't scan for movies. Here's why:") puts("\t#{e.code}: #{e.message}") raise else movies end
-
API 세부 정보는 AWS SDK for Ruby API 참조의 Scan을 참조하십시오.
-
- Rust
-
- SDK for Rust
-
참고
GitHub에 더 많은 내용이 있습니다. AWS코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. pub async fn list_items(client: &Client, table: &str, page_size: Option<i32>) -> Result<(), Error> { let page_size = page_size.unwrap_or(10); let items: Result<Vec<_>, _> = client .scan() .table_name(table) .limit(page_size) .into_paginator() .items() .send() .collect() .await; println!("Items in table (up to {page_size}):"); for item in items? { println!(" {:?}", item); } Ok(()) }
-
API 세부 정보는 AWS SDK for Rust API 참조의 Scan
을 참조하십시오.
-
- SAP ABAP
-
- SDK for SAP ABAP API
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. TRY. " Scan movies for rating greater than or equal to the rating specified DATA(lt_attributelist) = VALUE /aws1/cl_dynattributevalue=>tt_attributevaluelist( ( NEW /aws1/cl_dynattributevalue( iv_n = |{ iv_rating }| ) ) ). DATA(lt_filter_conditions) = VALUE /aws1/cl_dyncondition=>tt_filterconditionmap( ( VALUE /aws1/cl_dyncondition=>ts_filterconditionmap_maprow( key = 'rating' value = NEW /aws1/cl_dyncondition( it_attributevaluelist = lt_attributelist iv_comparisonoperator = |GE| ) ) ) ). oo_scan_result = lo_dyn->scan( iv_tablename = iv_table_name it_scanfilter = lt_filter_conditions ). DATA(lt_items) = oo_scan_result->get_items( ). LOOP AT lt_items INTO DATA(lo_item). " You can loop over to get individual attributes. DATA(lo_title) = lo_item[ key = 'title' ]-value. DATA(lo_year) = lo_item[ key = 'year' ]-value. ENDLOOP. DATA(lv_count) = oo_scan_result->get_count( ). MESSAGE 'Found ' && lv_count && ' items' TYPE 'I'. CATCH /aws1/cx_dynresourcenotfoundex. MESSAGE 'The table or index does not exist' TYPE 'E'. ENDTRY.
-
API 세부 정보는 AWSSDK for SAP ABAP API의 Scan을 참조하십시오.
-
- Swift
-
- SDK for Swift
-
참고
GitHub에 더 많은 내용이 있습니다. AWS코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. import AWSDynamoDB /// Return an array of `Movie` objects released in the specified range of /// years. /// /// - Parameters: /// - firstYear: The first year of movies to return. /// - lastYear: The last year of movies to return. /// - startKey: A starting point to resume processing; always use `nil`. /// /// - Returns: An array of `Movie` objects describing the matching movies. /// /// > Note: The `startKey` parameter is used by this function when /// recursively calling itself, and should always be `nil` when calling /// directly. /// func getMovies(firstYear: Int, lastYear: Int, startKey: [Swift.String: DynamoDBClientTypes.AttributeValue]? = nil) async throws -> [Movie] { do { var movieList: [Movie] = [] guard let client = self.ddbClient else { throw MoviesError.UninitializedClient } let input = ScanInput( consistentRead: true, exclusiveStartKey: startKey, expressionAttributeNames: [ "#y": "year" // `year` is a reserved word, so use `#y` instead. ], expressionAttributeValues: [ ":y1": .n(String(firstYear)), ":y2": .n(String(lastYear)) ], filterExpression: "#y BETWEEN :y1 AND :y2", tableName: self.tableName ) let pages = client.scanPaginated(input: input) for try await page in pages { guard let items = page.items else { print("Error: no items returned.") continue } // Build an array of `Movie` objects for the returned items. for item in items { let movie = try Movie(withItem: item) movieList.append(movie) } } return movieList } catch { print("ERROR: getMovies with scan:", dump(error)) throw error } }
-
API에 대한 세부 정보는 AWS Swift용 SDK API 참조의 Scan
을 참조하세요.
-
AWS SDK 개발자 가이드 및 코드 예시의 전체 목록은 AWS SDK와 함께 DynamoDB 사용 단원을 참조하세요. 이 주제에는 시작하기에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.