From 1dc86a1f2380ebf9e6ceaa18c3a7d02d8573caab Mon Sep 17 00:00:00 2001 From: Steven Meyer <108885656+meyertst-aws@users.noreply.github.com> Date: Thu, 15 Feb 2024 12:03:43 -0500 Subject: [PATCH] Bash,Cpp: Fix metadata and code layout (#6110) Changes to metadata to fix README links Reorganize Bash scenarios to align with UXR studies --- .doc_gen/metadata/glue_metadata.yaml | 26 +- .doc_gen/metadata/iam_metadata.yaml | 4 +- .doc_gen/metadata/lambda_metadata.yaml | 14 +- .doc_gen/metadata/s3_metadata.yaml | 2 + .../scenario_getting_started_movies.sh | 780 +++++++++--------- aws-cli/bash-linux/iam/README.md | 2 +- .../iam_create_user_assume_role_scenario.sh | 464 +++++------ aws-cli/bash-linux/s3/README.md | 2 +- aws-cli/bash-linux/s3/s3_getting_started.sh | 184 ++--- cpp/example_code/glue/README.md | 26 +- .../glue/glue_getting_started_scenario.cpp | 52 +- cpp/example_code/lambda/README.md | 14 +- .../get_started_with_functions_scenario.cpp | 28 +- 13 files changed, 801 insertions(+), 797 deletions(-) diff --git a/.doc_gen/metadata/glue_metadata.yaml b/.doc_gen/metadata/glue_metadata.yaml index f39a8bceb77..90195e403d2 100644 --- a/.doc_gen/metadata/glue_metadata.yaml +++ b/.doc_gen/metadata/glue_metadata.yaml @@ -132,7 +132,7 @@ glue_GetCrawler: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.get_crawler + - cpp.example_code.glue.GetCrawler Rust: versions: - sdk_version: 1 @@ -224,7 +224,7 @@ glue_CreateCrawler: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.create_crawler + - cpp.example_code.glue.CreateCrawler Rust: versions: - sdk_version: 1 @@ -316,7 +316,7 @@ glue_StartCrawler: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.start_crawler + - cpp.example_code.glue.StartCrawler Rust: versions: - sdk_version: 1 @@ -407,7 +407,7 @@ glue_GetDatabase: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.get_database + - cpp.example_code.glue.GetDatabase Rust: versions: - sdk_version: 1 @@ -489,7 +489,7 @@ glue_GetTables: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.get_tables + - cpp.example_code.glue.GetTables Rust: versions: - sdk_version: 1 @@ -563,7 +563,7 @@ glue_CreateJob: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.create_job + - cpp.example_code.glue.CreateJob Rust: versions: - sdk_version: 1 @@ -638,7 +638,7 @@ glue_StartJobRun: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.start_job_run + - cpp.example_code.glue.StartJobRun Rust: versions: - sdk_version: 1 @@ -709,7 +709,7 @@ glue_ListJobs: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.list_jobs + - cpp.example_code.glue.ListJobs Rust: versions: - sdk_version: 1 @@ -782,7 +782,7 @@ glue_GetJobRuns: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.get_job_runs + - cpp.example_code.glue.GetJobRuns services: glue: {GetJobRuns} glue_GetJobRun: @@ -847,7 +847,7 @@ glue_GetJobRun: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.get_job_run + - cpp.example_code.glue.GetJobRun Rust: versions: - sdk_version: 1 @@ -919,7 +919,7 @@ glue_DeleteJob: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.delete_job + - cpp.example_code.glue.DeleteJob Rust: versions: - sdk_version: 1 @@ -1052,7 +1052,7 @@ glue_DeleteDatabase: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.delete_database + - cpp.example_code.glue.DeleteDatabase Rust: versions: - sdk_version: 1 @@ -1124,7 +1124,7 @@ glue_DeleteCrawler: snippet_tags: - cpp.example_code.glue.client_configuration - cpp.example_code.glue.glue_client - - cpp.example_code.glue.delete_crawler + - cpp.example_code.glue.DeleteCrawler Rust: versions: - sdk_version: 1 diff --git a/.doc_gen/metadata/iam_metadata.yaml b/.doc_gen/metadata/iam_metadata.yaml index 3c2cad6b4b7..758de3a1484 100644 --- a/.doc_gen/metadata/iam_metadata.yaml +++ b/.doc_gen/metadata/iam_metadata.yaml @@ -3588,7 +3588,9 @@ iam_Scenario_CreateUserAssumeRole: excerpts: - description: snippet_tags: - - aws-cli.bash-linux.iam.iam_create_user_assume_role + - aws-cli.bash-linux.iam.iam_CreateUser_AssumeRole + - description: The &IAM; functions used in this scenario. + snippet_tags: - aws-cli.bash-linux.iam.GetUser - aws-cli.bash-linux.iam.CreateUser - aws-cli.bash-linux.iam.CreateAccessKey diff --git a/.doc_gen/metadata/lambda_metadata.yaml b/.doc_gen/metadata/lambda_metadata.yaml index d4099f2635f..aa8379a7646 100644 --- a/.doc_gen/metadata/lambda_metadata.yaml +++ b/.doc_gen/metadata/lambda_metadata.yaml @@ -150,7 +150,7 @@ lambda_CreateFunction: snippet_tags: - cpp.example_code.lambda.lambda_configuration - cpp.example_code.lambda.lambda_client - - cpp.example_code.lambda.create_function1 + - cpp.example_code.lambda.CreateFunction - cpp.example_code.lambda.create_function2 Rust: versions: @@ -259,7 +259,7 @@ lambda_DeleteFunction: snippet_tags: - cpp.example_code.lambda.lambda_configuration - cpp.example_code.lambda.lambda_client - - cpp.example_code.lambda.delete_function + - cpp.example_code.lambda.DeleteFunction Rust: versions: - sdk_version: 1 @@ -366,7 +366,7 @@ lambda_Invoke: snippet_tags: - cpp.example_code.lambda.lambda_configuration - cpp.example_code.lambda.lambda_client - - cpp.example_code.lambda.invoke_function1 + - cpp.example_code.lambda.Invoke - cpp.example_code.lambda.invoke_function2 Rust: versions: @@ -457,7 +457,7 @@ lambda_GetFunction: snippet_tags: - cpp.example_code.lambda.lambda_configuration - cpp.example_code.lambda.lambda_client - - cpp.example_code.lambda.get_function + - cpp.example_code.lambda.GetFunction Rust: versions: - sdk_version: 1 @@ -546,7 +546,7 @@ lambda_UpdateFunctionCode: snippet_tags: - cpp.example_code.lambda.lambda_configuration - cpp.example_code.lambda.lambda_client - - cpp.example_code.lambda.update_function_code + - cpp.example_code.lambda.UpdateFunctionCode Rust: versions: - sdk_version: 1 @@ -635,7 +635,7 @@ lambda_UpdateFunctionConfiguration: snippet_tags: - cpp.example_code.lambda.lambda_configuration - cpp.example_code.lambda.lambda_client - - cpp.example_code.lambda.update_function_configuration1 + - cpp.example_code.lambda.UpdateFunctionConfiguration - cpp.example_code.lambda.update_function_configuration2 Rust: versions: @@ -725,7 +725,7 @@ lambda_ListFunctions: snippet_tags: - cpp.example_code.lambda.lambda_configuration - cpp.example_code.lambda.lambda_client - - cpp.example_code.lambda.list_functions + - cpp.example_code.lambda.ListFunctions Rust: versions: - sdk_version: 1 diff --git a/.doc_gen/metadata/s3_metadata.yaml b/.doc_gen/metadata/s3_metadata.yaml index fb37105e49d..b7fa79a2323 100644 --- a/.doc_gen/metadata/s3_metadata.yaml +++ b/.doc_gen/metadata/s3_metadata.yaml @@ -2672,6 +2672,8 @@ s3_Scenario_GettingStarted: - description: snippet_tags: - aws-cli.bash-linux.s3.getting_started_scenario + - description: The &S3; functions used in this scenario. + snippet_tags: - aws-cli.bash-linux.s3.CreateBucket - aws-cli.bash-linux.s3.PutObject - aws-cli.bash-linux.s3.GetObject diff --git a/aws-cli/bash-linux/dynamodb/scenario_getting_started_movies.sh b/aws-cli/bash-linux/dynamodb/scenario_getting_started_movies.sh index 4b0cb19be1d..357ab1f08ce 100755 --- a/aws-cli/bash-linux/dynamodb/scenario_getting_started_movies.sh +++ b/aws-cli/bash-linux/dynamodb/scenario_getting_started_movies.sh @@ -33,303 +33,6 @@ # 9. Delete the table. (DeleteTable) # -############################################################################### -# function get_input -# -# This function gets user input from the command line. -# -# Outputs: -# User input to stdout. -# -# Returns: -# 0 -############################################################################### -function get_input() { - - if [ -z "${mock_input+x}" ]; then - read -r get_input_result - else - - if [ -n "${mock_input_array[*]}" ]; then - get_input_result="${mock_input_array[0]}" - # bashsupport disable=BP2001 - # shellcheck disable=SC2206 - mock_input_array=(${mock_input_array[@]:1}) - export mock_input_array - echo -n "$get_input_result" - else - get_input_result="y" - echo "MOCK_INPUT_ARRAY is empty" 1>&2 - exit 1 - fi - fi -} - -############################################################################### -# function clean_up -# -# This function cleans up the created resources. -# -# Returns: -# 0 - If successful. -# 1 - If an error occurred. -############################################################################### -function clean_up() { - local result=0 - local table_name=$1 - - if [ -n "$table_name" ]; then - if (dynamodb_delete_table -n "$table_name"); then - echo "Deleted DynamoDB table named $table_name" - else - errecho "The table failed to delete." - result=1 - fi - fi - - if [ -e "$key_schema_json_file" ]; then - rm "$key_schema_json_file" - fi - - if [ -e "$attribute_definitions_json_file" ]; then - rm $attribute_definitions_json_file"" - fi - - if [ -e "$item_json_file" ]; then - rm "$item_json_file" - fi - - if [ -e "$key_json_file" ]; then - rm "$key_json_file" - fi - - if [ -e "$batch_json_file" ]; then - rm "$batch_json_file" - fi - - if [ -e "$attribute_names_json_file" ]; then - rm "$attribute_names_json_file" - fi - - if [ -e "$attributes_values_json_file" ]; then - rm "$attributes_values_json_file" - fi - - return $result -} - -############################################################################### -# function get_yes_no_input -# -# This function requests a yes/no answer from the user. -# -# Parameters: -# $1 - The prompt. -# -# Returns: -# 0 - If yes. -# 1 - If no. -############################################################################### -function get_yes_no_input() { - if [ -z "$1" ]; then - echo "Internal error get_yes_no_input" - return 1 - fi - - local index=0 - local response="N" - while [[ $index -lt 10 ]]; do - index=$((index + 1)) - echo -n "$1" - get_input - - response=$(echo "$get_input_result" | tr '[:upper:]' '[:lower:]') - if [ "$response" = "y" ] || [ "$response" = "n" ]; then - break - else - echo -e "\nPlease enter or 'y' or 'n'." - fi - done - - echo - - if [ "$response" = "y" ]; then - return 0 - else - return 1 - fi -} - -############################################################################### -# function get_int_input -# -# This function requests a non-negative integer answer from the user. -# -# Parameters: -# $1 - The prompt. -# $2 - Optional inclusive low. -# #3 - Optional inclusive high. -# -# Returns: -# The input, -# And -# 0 - If successful. -# 1 - If an error occurred. -############################################################################### -function get_int_input() { - if [ -z "$1" ]; then - echo "Internal error get_int_input" - return 1 - fi - - local low=$2 - local high=$3 - - local index=0 - local response="" - local input_valid=false - while [[ $input_valid == false ]]; do - index=$((index + 1)) - if [[ index -gt 10 ]]; then - return 1 - fi - - echo -n "$1" - get_input - - # Remove leading integers. - # shellcheck disable=SC2001 - response=$(echo "$get_input_result" | sed "s/[[:digit:]]*//") - - # Non-empty string indicates invalid input. - if [[ -n "$response" ]]; then - - echo -e "Please enter an integer." - continue - fi - - response="$get_input_result" - - if [[ -z $low ]] || [[ -z $high ]]; then - break - fi - - if [[ $response -lt $low ]]; then - echo -e "Response must be greater than or equal to $low." - continue - fi - - if [[ $response -gt $high ]]; then - echo -e "Response must be less than or equal to $high." - continue - fi - - input_valid=true - done - - get_input_result="$response" - - return 0 -} - -############################################################################### -# function get_float_input -# -# This function requests a non-negative float answer from the user. -# -# Parameters: -# $1 - The prompt. -# $2 - Optional inclusive low. -# #3 - Optional inclusive high. -# -# Returns: -# The input, -# And -# 0 - If successful. -# 1 - If an error occurred. -############################################################################### -function get_float_input() { - if [ -z "$1" ]; then - echo "Internal error get_float_input" - return 1 - fi - - local low=$2 - local high=$3 - - local index=0 - local response="" - local input_valid=false - while [[ $input_valid == false ]]; do - index=$((index + 1)) - if [[ index -gt 10 ]]; then - return 1 - fi - - echo -n "$1" - get_input - - # Remove leading integers. - # shellcheck disable=SC2001 - response=$(echo "$get_input_result" | sed "s/[[:digit:]]*//") - - if [[ -n "$response" ]]; then # Remove decimal if present. - # shellcheck disable=SC2001 - response=$(echo "$response" | sed "s/^\.[[:digit:]]*//") - fi - - # Non-empty string indicates invalid input. - if [[ -n "$response" ]]; then - echo -e "Please enter a floating point number." - continue - fi - - response="$get_input_result" - - if [[ -z $low ]] || [[ -z $high ]]; then - break - fi - - if (($(echo "$response < $low" | bc -l))); then - echo -e "Response must be greater than or equal to $low." - continue - fi - - if (($(echo "$response > $high" | bc -l))); then - echo -e "Response must be less than or equal to $high." - continue - fi - - input_valid=true - done - - get_input_result="$response" - return 0 -} - -############################################################################### -# function echo_repeat -# -# This function prints a string 'n' times to stdout. -# -# Parameters: -# $1 - The string. -# $2 - Number of times to print the string. -# -# Outputs: -# String 'n' times to stdout. -# -# Returns: -# 0 -############################################################################### -function echo_repeat() { - local end=$2 i - for ((i = 0; i < end; i++)); do - echo -n "$1" - done - echo -} - # snippet-start:[aws-cli.bash-linux.dynamodb.scenario_getting_started_movies] ############################################################################### # function dynamodb_getting_started_movies @@ -464,136 +167,433 @@ function dynamodb_getting_started_movies() { return 1 fi - echo - echo_repeat "*" 88 - echo - - echo "We will now use batch write to upload 150 movie entries into the table." + echo + echo_repeat "*" 88 + echo + + echo "We will now use batch write to upload 150 movie entries into the table." + + local batch_json + for batch_json in movie_files/movies_*.json; do + echo "{ \"$table_name\" : $(<"$batch_json") }" >"$batch_json_file" + if dynamodb_batch_write_item -i "$batch_json_file" 1>/dev/null; then + echo "Entries in $batch_json added to table." + else + errecho "Batch write failed. This demo will exit." + clean_up "$table_name" + return 1 + fi + done + + local title="The Lord of the Rings: The Fellowship of the Ring" + local year="2001" + + if get_yes_no_input "Let's move on...do you want to get info about '$title'? (y/n) "; then + echo '{ + "year": {"N" :"'"$year"'"}, + "title": {"S" : "'"$title"'"} + }' >"$key_json_file" + local info + info=$(dynamodb_get_item -n "$table_name" -k "$key_json_file") + + # shellcheck disable=SC2181 + if [[ ${?} -ne 0 ]]; then + errecho "Get item failed. This demo will exit." + clean_up "$table_name" + return 1 + fi + + echo "Here is what I found:" + echo "$info" + fi + + local ask_for_year=true + while [[ "$ask_for_year" == true ]]; do + echo "Let's get a list of movies released in a given year." + get_int_input "Enter a year between 1972 and 2018: " "1972" "2018" + year=$get_input_result + echo '{ + "#n": "year" + }' >"$attribute_names_json_file" + + echo '{ + ":v": {"N" :"'"$year"'"} + }' >"$attributes_values_json_file" + + response=$(dynamodb_query -n "$table_name" -k "#n=:v" -a "$attribute_names_json_file" -v "$attributes_values_json_file") + + # shellcheck disable=SC2181 + if [[ ${?} -ne 0 ]]; then + errecho "Query table failed. This demo will exit." + clean_up "$table_name" + return 1 + fi + + echo "Here is what I found:" + echo "$response" + + if ! get_yes_no_input "Try another year? (y/n) "; then + ask_for_year=false + fi + done + + echo "Now let's scan for movies released in a range of years. Enter a year: " + get_int_input "Enter a year between 1972 and 2018: " "1972" "2018" + local start=$get_input_result + + get_int_input "Enter another year: " "1972" "2018" + local end=$get_input_result + + echo '{ + "#n": "year" + }' >"$attribute_names_json_file" + + echo '{ + ":v1": {"N" : "'"$start"'"}, + ":v2": {"N" : "'"$end"'"} + }' >"$attributes_values_json_file" + + response=$(dynamodb_scan -n "$table_name" -f "#n BETWEEN :v1 AND :v2" -a "$attribute_names_json_file" -v "$attributes_values_json_file") + + # shellcheck disable=SC2181 + if [[ ${?} -ne 0 ]]; then + errecho "Scan table failed. This demo will exit." + clean_up "$table_name" + return 1 + fi + + echo "Here is what I found:" + echo "$response" + + echo + echo_repeat "*" 88 + echo + + echo "Let's remove your movie '$added_title' from the table." + + if get_yes_no_input "Do you want to remove '$added_title'? (y/n) "; then + echo '{ + "year": {"N" :"'"$added_year"'"}, + "title": {"S" : "'"$added_title"'"} + }' >"$key_json_file" + + if ! dynamodb_delete_item -n "$table_name" -k "$key_json_file"; then + errecho "Delete item failed. This demo will exit." + clean_up "$table_name" + return 1 + fi + fi + + if get_yes_no_input "Do you want to delete the table '$table_name'? (y/n) "; then + if ! clean_up "$table_name"; then + return 1 + fi + else + if ! clean_up; then + return 1 + fi + fi + + return 0 +} +# snippet-end:[aws-cli.bash-linux.dynamodb.scenario_getting_started_movies] + +############################################################################### +# function get_input +# +# This function gets user input from the command line. +# +# Outputs: +# User input to stdout. +# +# Returns: +# 0 +############################################################################### +function get_input() { + + if [ -z "${mock_input+x}" ]; then + read -r get_input_result + else + + if [ -n "${mock_input_array[*]}" ]; then + get_input_result="${mock_input_array[0]}" + # bashsupport disable=BP2001 + # shellcheck disable=SC2206 + mock_input_array=(${mock_input_array[@]:1}) + export mock_input_array + echo -n "$get_input_result" + else + get_input_result="y" + echo "MOCK_INPUT_ARRAY is empty" 1>&2 + exit 1 + fi + fi +} + +############################################################################### +# function clean_up +# +# This function cleans up the created resources. +# +# Returns: +# 0 - If successful. +# 1 - If an error occurred. +############################################################################### +function clean_up() { + local result=0 + local table_name=$1 + + if [ -n "$table_name" ]; then + if (dynamodb_delete_table -n "$table_name"); then + echo "Deleted DynamoDB table named $table_name" + else + errecho "The table failed to delete." + result=1 + fi + fi + + if [ -e "$key_schema_json_file" ]; then + rm "$key_schema_json_file" + fi + + if [ -e "$attribute_definitions_json_file" ]; then + rm $attribute_definitions_json_file"" + fi + + if [ -e "$item_json_file" ]; then + rm "$item_json_file" + fi + + if [ -e "$key_json_file" ]; then + rm "$key_json_file" + fi + + if [ -e "$batch_json_file" ]; then + rm "$batch_json_file" + fi + + if [ -e "$attribute_names_json_file" ]; then + rm "$attribute_names_json_file" + fi + + if [ -e "$attributes_values_json_file" ]; then + rm "$attributes_values_json_file" + fi + + return $result +} + +############################################################################### +# function get_yes_no_input +# +# This function requests a yes/no answer from the user. +# +# Parameters: +# $1 - The prompt. +# +# Returns: +# 0 - If yes. +# 1 - If no. +############################################################################### +function get_yes_no_input() { + if [ -z "$1" ]; then + echo "Internal error get_yes_no_input" + return 1 + fi + + local index=0 + local response="N" + while [[ $index -lt 10 ]]; do + index=$((index + 1)) + echo -n "$1" + get_input - local batch_json - for batch_json in movie_files/movies_*.json; do - echo "{ \"$table_name\" : $(<"$batch_json") }" >"$batch_json_file" - if dynamodb_batch_write_item -i "$batch_json_file" 1>/dev/null; then - echo "Entries in $batch_json added to table." + response=$(echo "$get_input_result" | tr '[:upper:]' '[:lower:]') + if [ "$response" = "y" ] || [ "$response" = "n" ]; then + break else - errecho "Batch write failed. This demo will exit." - clean_up "$table_name" - return 1 + echo -e "\nPlease enter or 'y' or 'n'." fi done - local title="The Lord of the Rings: The Fellowship of the Ring" - local year="2001" + echo - if get_yes_no_input "Let's move on...do you want to get info about '$title'? (y/n) "; then - echo '{ - "year": {"N" :"'"$year"'"}, - "title": {"S" : "'"$title"'"} - }' >"$key_json_file" - local info - info=$(dynamodb_get_item -n "$table_name" -k "$key_json_file") + if [ "$response" = "y" ]; then + return 0 + else + return 1 + fi +} - # shellcheck disable=SC2181 - if [[ ${?} -ne 0 ]]; then - errecho "Get item failed. This demo will exit." - clean_up "$table_name" +############################################################################### +# function get_int_input +# +# This function requests a non-negative integer answer from the user. +# +# Parameters: +# $1 - The prompt. +# $2 - Optional inclusive low. +# #3 - Optional inclusive high. +# +# Returns: +# The input, +# And +# 0 - If successful. +# 1 - If an error occurred. +############################################################################### +function get_int_input() { + if [ -z "$1" ]; then + echo "Internal error get_int_input" + return 1 + fi + + local low=$2 + local high=$3 + + local index=0 + local response="" + local input_valid=false + while [[ $input_valid == false ]]; do + index=$((index + 1)) + if [[ index -gt 10 ]]; then return 1 fi - echo "Here is what I found:" - echo "$info" - fi - - local ask_for_year=true - while [[ "$ask_for_year" == true ]]; do - echo "Let's get a list of movies released in a given year." - get_int_input "Enter a year between 1972 and 2018: " "1972" "2018" - year=$get_input_result - echo '{ - "#n": "year" - }' >"$attribute_names_json_file" + echo -n "$1" + get_input - echo '{ - ":v": {"N" :"'"$year"'"} - }' >"$attributes_values_json_file" + # Remove leading integers. + # shellcheck disable=SC2001 + response=$(echo "$get_input_result" | sed "s/[[:digit:]]*//") - response=$(dynamodb_query -n "$table_name" -k "#n=:v" -a "$attribute_names_json_file" -v "$attributes_values_json_file") + # Non-empty string indicates invalid input. + if [[ -n "$response" ]]; then - # shellcheck disable=SC2181 - if [[ ${?} -ne 0 ]]; then - errecho "Query table failed. This demo will exit." - clean_up "$table_name" - return 1 + echo -e "Please enter an integer." + continue fi - echo "Here is what I found:" - echo "$response" + response="$get_input_result" - if ! get_yes_no_input "Try another year? (y/n) "; then - ask_for_year=false + if [[ -z $low ]] || [[ -z $high ]]; then + break fi - done - echo "Now let's scan for movies released in a range of years. Enter a year: " - get_int_input "Enter a year between 1972 and 2018: " "1972" "2018" - local start=$get_input_result + if [[ $response -lt $low ]]; then + echo -e "Response must be greater than or equal to $low." + continue + fi - get_int_input "Enter another year: " "1972" "2018" - local end=$get_input_result + if [[ $response -gt $high ]]; then + echo -e "Response must be less than or equal to $high." + continue + fi - echo '{ - "#n": "year" - }' >"$attribute_names_json_file" + input_valid=true + done - echo '{ - ":v1": {"N" : "'"$start"'"}, - ":v2": {"N" : "'"$end"'"} - }' >"$attributes_values_json_file" + get_input_result="$response" - response=$(dynamodb_scan -n "$table_name" -f "#n BETWEEN :v1 AND :v2" -a "$attribute_names_json_file" -v "$attributes_values_json_file") + return 0 +} - # shellcheck disable=SC2181 - if [[ ${?} -ne 0 ]]; then - errecho "Scan table failed. This demo will exit." - clean_up "$table_name" +############################################################################### +# function get_float_input +# +# This function requests a non-negative float answer from the user. +# +# Parameters: +# $1 - The prompt. +# $2 - Optional inclusive low. +# #3 - Optional inclusive high. +# +# Returns: +# The input, +# And +# 0 - If successful. +# 1 - If an error occurred. +############################################################################### +function get_float_input() { + if [ -z "$1" ]; then + echo "Internal error get_float_input" return 1 fi - echo "Here is what I found:" - echo "$response" + local low=$2 + local high=$3 - echo - echo_repeat "*" 88 - echo + local index=0 + local response="" + local input_valid=false + while [[ $input_valid == false ]]; do + index=$((index + 1)) + if [[ index -gt 10 ]]; then + return 1 + fi - echo "Let's remove your movie '$added_title' from the table." + echo -n "$1" + get_input - if get_yes_no_input "Do you want to remove '$added_title'? (y/n) "; then - echo '{ - "year": {"N" :"'"$added_year"'"}, - "title": {"S" : "'"$added_title"'"} - }' >"$key_json_file" + # Remove leading integers. + # shellcheck disable=SC2001 + response=$(echo "$get_input_result" | sed "s/[[:digit:]]*//") - if ! dynamodb_delete_item -n "$table_name" -k "$key_json_file"; then - errecho "Delete item failed. This demo will exit." - clean_up "$table_name" - return 1 + if [[ -n "$response" ]]; then # Remove decimal if present. + # shellcheck disable=SC2001 + response=$(echo "$response" | sed "s/^\.[[:digit:]]*//") fi - fi - if get_yes_no_input "Do you want to delete the table '$table_name'? (y/n) "; then - if ! clean_up "$table_name"; then - return 1 + # Non-empty string indicates invalid input. + if [[ -n "$response" ]]; then + echo -e "Please enter a floating point number." + continue fi - else - if ! clean_up; then - return 1 + + response="$get_input_result" + + if [[ -z $low ]] || [[ -z $high ]]; then + break + fi + + if (($(echo "$response < $low" | bc -l))); then + echo -e "Response must be greater than or equal to $low." + continue + fi + + if (($(echo "$response > $high" | bc -l))); then + echo -e "Response must be less than or equal to $high." + continue fi - fi + input_valid=true + done + + get_input_result="$response" return 0 } -# snippet-end:[aws-cli.bash-linux.dynamodb.scenario_getting_started_movies] + +############################################################################### +# function echo_repeat +# +# This function prints a string 'n' times to stdout. +# +# Parameters: +# $1 - The string. +# $2 - Number of times to print the string. +# +# Outputs: +# String 'n' times to stdout. +# +# Returns: +# 0 +############################################################################### +function echo_repeat() { + local end=$2 i + for ((i = 0; i < end; i++)); do + echo -n "$1" + done + echo +} ############################################################################### # function main diff --git a/aws-cli/bash-linux/iam/README.md b/aws-cli/bash-linux/iam/README.md index 9f798d49bed..c42bc992fc1 100644 --- a/aws-cli/bash-linux/iam/README.md +++ b/aws-cli/bash-linux/iam/README.md @@ -52,7 +52,7 @@ Code excerpts that show you how to call individual service functions. Code examples that show you how to accomplish a specific task by calling multiple functions within the same service. -- [Create a user and assume a role](iam_operations.sh) +- [Create a user and assume a role](iam_create_user_assume_role_scenario.sh) diff --git a/aws-cli/bash-linux/iam/iam_create_user_assume_role_scenario.sh b/aws-cli/bash-linux/iam/iam_create_user_assume_role_scenario.sh index c115f9d1aba..b8aa7aa5c45 100755 --- a/aws-cli/bash-linux/iam/iam_create_user_assume_role_scenario.sh +++ b/aws-cli/bash-linux/iam/iam_create_user_assume_role_scenario.sh @@ -29,6 +29,238 @@ # 8. List objects in the bucket using the assumed role's credentials. This should succeed. # 9. Delete all the created resources. +# snippet-start:[aws-cli.bash-linux.iam.iam_CreateUser_AssumeRole] +############################################################################### +# function iam_create_user_assume_role +# +# Scenario to create an IAM user, create an IAM role, and apply the role to the user. +# +# "IAM access" permissions are needed to run this code. +# "STS assume role" permissions are needed to run this code. (Note: It might be necessary to +# create a custom policy). +# +# Returns: +# 0 - If successful. +# 1 - If an error occurred. +############################################################################### +function iam_create_user_assume_role() { + { + if [ "$IAM_OPERATIONS_SOURCED" != "True" ]; then + + source ./iam_operations.sh + fi + } + + echo_repeat "*" 88 + echo "Welcome to the IAM create user and assume role demo." + echo + echo "This demo will create an IAM user, create an IAM role, and apply the role to the user." + echo_repeat "*" 88 + echo + + echo -n "Enter a name for a new IAM user: " + get_input + user_name=$get_input_result + + local user_arn + user_arn=$(iam_create_user -u "$user_name") + + # shellcheck disable=SC2181 + if [[ ${?} == 0 ]]; then + echo "Created demo IAM user named $user_name" + else + errecho "$user_arn" + errecho "The user failed to create. This demo will exit." + return 1 + fi + + local access_key_response + access_key_response=$(iam_create_user_access_key -u "$user_name") + # shellcheck disable=SC2181 + if [[ ${?} != 0 ]]; then + errecho "The access key failed to create. This demo will exit." + clean_up "$user_name" + return 1 + fi + + IFS=$'\t ' read -r -a access_key_values <<<"$access_key_response" + local key_name=${access_key_values[0]} + local key_secret=${access_key_values[1]} + + echo "Created access key named $key_name" + + echo "Wait 10 seconds for the user to be ready." + sleep 10 + echo_repeat "*" 88 + echo + + local iam_role_name + iam_role_name=$(generate_random_name "test-role") + echo "Creating a role named $iam_role_name with user $user_name as the principal." + + local assume_role_policy_document="{ + \"Version\": \"2012-10-17\", + \"Statement\": [{ + \"Effect\": \"Allow\", + \"Principal\": {\"AWS\": \"$user_arn\"}, + \"Action\": \"sts:AssumeRole\" + }] + }" + + local role_arn + role_arn=$(iam_create_role -n "$iam_role_name" -p "$assume_role_policy_document") + + # shellcheck disable=SC2181 + if [ ${?} == 0 ]; then + echo "Created IAM role named $iam_role_name" + else + errecho "The role failed to create. This demo will exit." + clean_up "$user_name" "$key_name" + return 1 + fi + + local policy_name + policy_name=$(generate_random_name "test-policy") + local policy_document="{ + \"Version\": \"2012-10-17\", + \"Statement\": [{ + \"Effect\": \"Allow\", + \"Action\": \"s3:ListAllMyBuckets\", + \"Resource\": \"arn:aws:s3:::*\"}]}" + + local policy_arn + policy_arn=$(iam_create_policy -n "$policy_name" -p "$policy_document") + # shellcheck disable=SC2181 + if [[ ${?} == 0 ]]; then + echo "Created IAM policy named $policy_name" + else + errecho "The policy failed to create." + clean_up "$user_name" "$key_name" "$iam_role_name" + return 1 + fi + + if (iam_attach_role_policy -n "$iam_role_name" -p "$policy_arn"); then + echo "Attached policy $policy_arn to role $iam_role_name" + else + errecho "The policy failed to attach." + clean_up "$user_name" "$key_name" "$iam_role_name" "$policy_arn" + return 1 + fi + + local assume_role_policy_document="{ + \"Version\": \"2012-10-17\", + \"Statement\": [{ + \"Effect\": \"Allow\", + \"Action\": \"sts:AssumeRole\", + \"Resource\": \"$role_arn\"}]}" + + local assume_role_policy_name + assume_role_policy_name=$(generate_random_name "test-assume-role-") + + # shellcheck disable=SC2181 + local assume_role_policy_arn + assume_role_policy_arn=$(iam_create_policy -n "$assume_role_policy_name" -p "$assume_role_policy_document") + # shellcheck disable=SC2181 + if [ ${?} == 0 ]; then + echo "Created IAM policy named $assume_role_policy_name for sts assume role" + else + errecho "The policy failed to create." + clean_up "$user_name" "$key_name" "$iam_role_name" "$policy_arn" "$policy_arn" + return 1 + fi + + echo "Wait 10 seconds to give AWS time to propagate these new resources and connections." + sleep 10 + echo_repeat "*" 88 + echo + + echo "Try to list buckets without the new user assuming the role." + echo_repeat "*" 88 + echo + + # Set the environment variables for the created user. + # bashsupport disable=BP2001 + export AWS_ACCESS_KEY_ID=$key_name + # bashsupport disable=BP2001 + export AWS_SECRET_ACCESS_KEY=$key_secret + + local buckets + buckets=$(s3_list_buckets) + + # shellcheck disable=SC2181 + if [ ${?} == 0 ]; then + local bucket_count + bucket_count=$(echo "$buckets" | wc -w | xargs) + echo "There are $bucket_count buckets in the account. This should not have happened." + else + errecho "Because the role with permissions has not been assumed, listing buckets failed." + fi + + echo + echo_repeat "*" 88 + echo "Now assume the role $iam_role_name and list the buckets." + echo_repeat "*" 88 + echo + + local credentials + + credentials=$(sts_assume_role -r "$role_arn" -n "AssumeRoleDemoSession") + # shellcheck disable=SC2181 + if [ ${?} == 0 ]; then + echo "Assumed role $iam_role_name" + else + errecho "Failed to assume role." + export AWS_ACCESS_KEY_ID="" + export AWS_SECRET_ACCESS_KEY="" + clean_up "$user_name" "$key_name" "$iam_role_name" "$policy_arn" "$policy_arn" "$assume_role_policy_arn" + return 1 + fi + + IFS=$'\t ' read -r -a credentials <<<"$credentials" + + export AWS_ACCESS_KEY_ID=${credentials[0]} + export AWS_SECRET_ACCESS_KEY=${credentials[1]} + # bashsupport disable=BP2001 + export AWS_SESSION_TOKEN=${credentials[2]} + + buckets=$(s3_list_buckets) + + # shellcheck disable=SC2181 + if [ ${?} == 0 ]; then + local bucket_count + bucket_count=$(echo "$buckets" | wc -w | xargs) + echo "There are $bucket_count buckets in the account. Listing buckets succeeded because of " + echo "the assumed role." + else + errecho "Failed to list buckets. This should not happen." + export AWS_ACCESS_KEY_ID="" + export AWS_SECRET_ACCESS_KEY="" + export AWS_SESSION_TOKEN="" + clean_up "$user_name" "$key_name" "$iam_role_name" "$policy_arn" "$policy_arn" "$assume_role_policy_arn" + return 1 + fi + + local result=0 + export AWS_ACCESS_KEY_ID="" + export AWS_SECRET_ACCESS_KEY="" + + echo + echo_repeat "*" 88 + echo "The created resources will now be deleted." + echo_repeat "*" 88 + echo + + clean_up "$user_name" "$key_name" "$iam_role_name" "$policy_arn" "$policy_arn" "$assume_role_policy_arn" + + # shellcheck disable=SC2181 + if [[ ${?} -ne 0 ]]; then + result=1 + fi + + return $result +} +# snippet-end:[aws-cli.bash-linux.iam.iam_CreateUser_AssumeRole] + ############################################################################### # function get_input # @@ -301,238 +533,6 @@ function sts_assume_role() { } # snippet-end:[aws-cli.bash-linux.sts.assume-role] -# snippet-start:[aws-cli.bash-linux.iam.iam_create_user_assume_role] -############################################################################### -# function iam_create_user_assume_role -# -# Scenario to create an IAM user, create an IAM role, and apply the role to the user. -# -# "IAM access" permissions are needed to run this code. -# "STS assume role" permissions are needed to run this code. (Note: It might be necessary to -# create a custom policy). -# -# Returns: -# 0 - If successful. -# 1 - If an error occurred. -############################################################################### -function iam_create_user_assume_role() { - { - if [ "$IAM_OPERATIONS_SOURCED" != "True" ]; then - - source ./iam_operations.sh - fi - } - - echo_repeat "*" 88 - echo "Welcome to the IAM create user and assume role demo." - echo - echo "This demo will create an IAM user, create an IAM role, and apply the role to the user." - echo_repeat "*" 88 - echo - - echo -n "Enter a name for a new IAM user: " - get_input - user_name=$get_input_result - - local user_arn - user_arn=$(iam_create_user -u "$user_name") - - # shellcheck disable=SC2181 - if [[ ${?} == 0 ]]; then - echo "Created demo IAM user named $user_name" - else - errecho "$user_arn" - errecho "The user failed to create. This demo will exit." - return 1 - fi - - local access_key_response - access_key_response=$(iam_create_user_access_key -u "$user_name") - # shellcheck disable=SC2181 - if [[ ${?} != 0 ]]; then - errecho "The access key failed to create. This demo will exit." - clean_up "$user_name" - return 1 - fi - - IFS=$'\t ' read -r -a access_key_values <<<"$access_key_response" - local key_name=${access_key_values[0]} - local key_secret=${access_key_values[1]} - - echo "Created access key named $key_name" - - echo "Wait 10 seconds for the user to be ready." - sleep 10 - echo_repeat "*" 88 - echo - - local iam_role_name - iam_role_name=$(generate_random_name "test-role") - echo "Creating a role named $iam_role_name with user $user_name as the principal." - - local assume_role_policy_document="{ - \"Version\": \"2012-10-17\", - \"Statement\": [{ - \"Effect\": \"Allow\", - \"Principal\": {\"AWS\": \"$user_arn\"}, - \"Action\": \"sts:AssumeRole\" - }] - }" - - local role_arn - role_arn=$(iam_create_role -n "$iam_role_name" -p "$assume_role_policy_document") - - # shellcheck disable=SC2181 - if [ ${?} == 0 ]; then - echo "Created IAM role named $iam_role_name" - else - errecho "The role failed to create. This demo will exit." - clean_up "$user_name" "$key_name" - return 1 - fi - - local policy_name - policy_name=$(generate_random_name "test-policy") - local policy_document="{ - \"Version\": \"2012-10-17\", - \"Statement\": [{ - \"Effect\": \"Allow\", - \"Action\": \"s3:ListAllMyBuckets\", - \"Resource\": \"arn:aws:s3:::*\"}]}" - - local policy_arn - policy_arn=$(iam_create_policy -n "$policy_name" -p "$policy_document") - # shellcheck disable=SC2181 - if [[ ${?} == 0 ]]; then - echo "Created IAM policy named $policy_name" - else - errecho "The policy failed to create." - clean_up "$user_name" "$key_name" "$iam_role_name" - return 1 - fi - - if (iam_attach_role_policy -n "$iam_role_name" -p "$policy_arn"); then - echo "Attached policy $policy_arn to role $iam_role_name" - else - errecho "The policy failed to attach." - clean_up "$user_name" "$key_name" "$iam_role_name" "$policy_arn" - return 1 - fi - - local assume_role_policy_document="{ - \"Version\": \"2012-10-17\", - \"Statement\": [{ - \"Effect\": \"Allow\", - \"Action\": \"sts:AssumeRole\", - \"Resource\": \"$role_arn\"}]}" - - local assume_role_policy_name - assume_role_policy_name=$(generate_random_name "test-assume-role-") - - # shellcheck disable=SC2181 - local assume_role_policy_arn - assume_role_policy_arn=$(iam_create_policy -n "$assume_role_policy_name" -p "$assume_role_policy_document") - # shellcheck disable=SC2181 - if [ ${?} == 0 ]; then - echo "Created IAM policy named $assume_role_policy_name for sts assume role" - else - errecho "The policy failed to create." - clean_up "$user_name" "$key_name" "$iam_role_name" "$policy_arn" "$policy_arn" - return 1 - fi - - echo "Wait 10 seconds to give AWS time to propagate these new resources and connections." - sleep 10 - echo_repeat "*" 88 - echo - - echo "Try to list buckets without the new user assuming the role." - echo_repeat "*" 88 - echo - - # Set the environment variables for the created user. - # bashsupport disable=BP2001 - export AWS_ACCESS_KEY_ID=$key_name - # bashsupport disable=BP2001 - export AWS_SECRET_ACCESS_KEY=$key_secret - - local buckets - buckets=$(s3_list_buckets) - - # shellcheck disable=SC2181 - if [ ${?} == 0 ]; then - local bucket_count - bucket_count=$(echo "$buckets" | wc -w | xargs) - echo "There are $bucket_count buckets in the account. This should not have happened." - else - errecho "Because the role with permissions has not been assumed, listing buckets failed." - fi - - echo - echo_repeat "*" 88 - echo "Now assume the role $iam_role_name and list the buckets." - echo_repeat "*" 88 - echo - - local credentials - - credentials=$(sts_assume_role -r "$role_arn" -n "AssumeRoleDemoSession") - # shellcheck disable=SC2181 - if [ ${?} == 0 ]; then - echo "Assumed role $iam_role_name" - else - errecho "Failed to assume role." - export AWS_ACCESS_KEY_ID="" - export AWS_SECRET_ACCESS_KEY="" - clean_up "$user_name" "$key_name" "$iam_role_name" "$policy_arn" "$policy_arn" "$assume_role_policy_arn" - return 1 - fi - - IFS=$'\t ' read -r -a credentials <<<"$credentials" - - export AWS_ACCESS_KEY_ID=${credentials[0]} - export AWS_SECRET_ACCESS_KEY=${credentials[1]} - # bashsupport disable=BP2001 - export AWS_SESSION_TOKEN=${credentials[2]} - - buckets=$(s3_list_buckets) - - # shellcheck disable=SC2181 - if [ ${?} == 0 ]; then - local bucket_count - bucket_count=$(echo "$buckets" | wc -w | xargs) - echo "There are $bucket_count buckets in the account. Listing buckets succeeded because of " - echo "the assumed role." - else - errecho "Failed to list buckets. This should not happen." - export AWS_ACCESS_KEY_ID="" - export AWS_SECRET_ACCESS_KEY="" - export AWS_SESSION_TOKEN="" - clean_up "$user_name" "$key_name" "$iam_role_name" "$policy_arn" "$policy_arn" "$assume_role_policy_arn" - return 1 - fi - - local result=0 - export AWS_ACCESS_KEY_ID="" - export AWS_SECRET_ACCESS_KEY="" - - echo - echo_repeat "*" 88 - echo "The created resources will now be deleted." - echo_repeat "*" 88 - echo - - clean_up "$user_name" "$key_name" "$iam_role_name" "$policy_arn" "$policy_arn" "$assume_role_policy_arn" - - # shellcheck disable=SC2181 - if [[ ${?} -ne 0 ]]; then - result=1 - fi - - return $result -} -# snippet-end:[aws-cli.bash-linux.iam.iam_create_user_assume_role] - ############################################################################### # function main # diff --git a/aws-cli/bash-linux/s3/README.md b/aws-cli/bash-linux/s3/README.md index 36ec5fd101e..b22a7fac9f4 100644 --- a/aws-cli/bash-linux/s3/README.md +++ b/aws-cli/bash-linux/s3/README.md @@ -48,7 +48,7 @@ Code excerpts that show you how to call individual service functions. Code examples that show you how to accomplish a specific task by calling multiple functions within the same service. -- [Get started with buckets and objects](bucket-lifecycle-operations/bucket_operations.sh) +- [Get started with buckets and objects](s3_getting_started.sh) diff --git a/aws-cli/bash-linux/s3/s3_getting_started.sh b/aws-cli/bash-linux/s3/s3_getting_started.sh index b1305803f65..c85cc61ae38 100755 --- a/aws-cli/bash-linux/s3/s3_getting_started.sh +++ b/aws-cli/bash-linux/s3/s3_getting_started.sh @@ -27,98 +27,6 @@ # 7. Delete the bucket. # -get_input_result="" - -############################################################################### -# function get_input -# -# This function gets user input from the command line. -# -# Outputs: -# User input to stdout. -# -# Returns: -# 0 -############################################################################### -function get_input() { - if [ -z "${mock_input+x}" ]; then - read -r get_input_result - else - if [ -n "${mock_input_array[*]}" ]; then - get_input_result="${mock_input_array[0]}" - mock_input_array=("${mock_input_array[@]:1}") - echo -n "$get_input_result" - else - get_input_result="y" - echo "MOCK_INPUT_ARRAY is empty" 1>&2 - fi - fi -} - -############################################################################### -# function yes_no_input -# -# This function requests a yes/no answer from the user, following to a prompt. -# -# Parameters: -# $1 - The prompt. -# -# Returns: -# 0 - If yes. -# 1 - If no. -############################################################################### -function yes_no_input() { - if [ -z "$1" ]; then - echo "Internal error yes_no_input" - return 1 - fi - - local index=0 - local response="N" - while [[ $index -lt 10 ]]; do - index=$((index + 1)) - echo -n "$1" - get_input - response=$(echo "$get_input_result" | tr '[:upper:]' '[:lower:]') - if [ "$response" = "y" ] || [ "$response" = "n" ]; then - break - else - echo -e "\nPlease enter or 'y' or 'n'." - fi - done - - echo - - if [ "$response" = "y" ]; then - return 0 - else - return 1 - fi -} - -############################################################################### -# function echo_repeat -# -# This function prints a string 'n' times to stdout. -# -# Parameters: -# $1 - The string. -# $2 - Number of times to print the string. -# -# Outputs: -# String 'n' times to stdout. -# -# Returns: -# 0 -############################################################################### -function echo_repeat() { - local end=$2 - for ((i = 0; i < end; i++)); do - echo -n "$1" - done - echo -} - # snippet-start:[aws-cli.bash-linux.s3.getting_started_scenario] ############################################################################### # function s3_getting_started @@ -231,11 +139,103 @@ function s3_getting_started() { } # snippet-end:[aws-cli.bash-linux.s3.getting_started_scenario] +############################################################################### +# function get_input +# +# This function gets user input from the command line. +# +# Outputs: +# User input to stdout. +# +# Returns: +# 0 +############################################################################### +function get_input() { + if [ -z "${mock_input+x}" ]; then + read -r get_input_result + else + if [ -n "${mock_input_array[*]}" ]; then + get_input_result="${mock_input_array[0]}" + mock_input_array=("${mock_input_array[@]:1}") + echo -n "$get_input_result" + else + get_input_result="y" + echo "MOCK_INPUT_ARRAY is empty" 1>&2 + fi + fi +} + +############################################################################### +# function yes_no_input +# +# This function requests a yes/no answer from the user, following to a prompt. +# +# Parameters: +# $1 - The prompt. +# +# Returns: +# 0 - If yes. +# 1 - If no. +############################################################################### +function yes_no_input() { + if [ -z "$1" ]; then + echo "Internal error yes_no_input" + return 1 + fi + + local index=0 + local response="N" + while [[ $index -lt 10 ]]; do + index=$((index + 1)) + echo -n "$1" + get_input + response=$(echo "$get_input_result" | tr '[:upper:]' '[:lower:]') + if [ "$response" = "y" ] || [ "$response" = "n" ]; then + break + else + echo -e "\nPlease enter or 'y' or 'n'." + fi + done + + echo + + if [ "$response" = "y" ]; then + return 0 + else + return 1 + fi +} + +############################################################################### +# function echo_repeat +# +# This function prints a string 'n' times to stdout. +# +# Parameters: +# $1 - The string. +# $2 - Number of times to print the string. +# +# Outputs: +# String 'n' times to stdout. +# +# Returns: +# 0 +############################################################################### +function echo_repeat() { + local end=$2 + for ((i = 0; i < end; i++)); do + echo -n "$1" + done + echo +} + ############################################################################### # function main # ############################################################################### function main() { + get_input_result="" + s3_getting_started } diff --git a/cpp/example_code/glue/README.md b/cpp/example_code/glue/README.md index 522a17b174c..558e76aeac3 100644 --- a/cpp/example_code/glue/README.md +++ b/cpp/example_code/glue/README.md @@ -46,19 +46,19 @@ Next, for information on code example structures and how to build and run the ex Code excerpts that show you how to call individual service functions. -- [Create a crawler](glue_getting_started_scenario.cpp#L869) (`CreateCrawler`) -- [Create a job definition](glue_getting_started_scenario.cpp#L869) (`CreateJob`) -- [Delete a crawler](glue_getting_started_scenario.cpp#L869) (`DeleteCrawler`) -- [Delete a database from the Data Catalog](glue_getting_started_scenario.cpp#L869) (`DeleteDatabase`) -- [Delete a job definition](glue_getting_started_scenario.cpp#L869) (`DeleteJob`) -- [Get a crawler](glue_getting_started_scenario.cpp#L869) (`GetCrawler`) -- [Get a database from the Data Catalog](glue_getting_started_scenario.cpp#L869) (`GetDatabase`) -- [Get a job run](glue_getting_started_scenario.cpp#L869) (`GetJobRun`) -- [Get runs of a job](glue_getting_started_scenario.cpp#L869) (`GetJobRuns`) -- [Get tables from a database](glue_getting_started_scenario.cpp#L869) (`GetTables`) -- [List job definitions](glue_getting_started_scenario.cpp#L869) (`ListJobs`) -- [Start a crawler](glue_getting_started_scenario.cpp#L869) (`StartCrawler`) -- [Start a job run](glue_getting_started_scenario.cpp#L869) (`StartJobRun`) +- [Create a crawler](glue_getting_started_scenario.cpp#L181) (`CreateCrawler`) +- [Create a job definition](glue_getting_started_scenario.cpp#L364) (`CreateJob`) +- [Delete a crawler](glue_getting_started_scenario.cpp#L674) (`DeleteCrawler`) +- [Delete a database from the Data Catalog](glue_getting_started_scenario.cpp#L654) (`DeleteDatabase`) +- [Delete a job definition](glue_getting_started_scenario.cpp#L634) (`DeleteJob`) +- [Get a crawler](glue_getting_started_scenario.cpp#L210) (`GetCrawler`) +- [Get a database from the Data Catalog](glue_getting_started_scenario.cpp#L302) (`GetDatabase`) +- [Get a job run](glue_getting_started_scenario.cpp#L590) (`GetJobRun`) +- [Get runs of a job](glue_getting_started_scenario.cpp#L555) (`GetJobRuns`) +- [Get tables from a database](glue_getting_started_scenario.cpp#L327) (`GetTables`) +- [List job definitions](glue_getting_started_scenario.cpp#L524) (`ListJobs`) +- [Start a crawler](glue_getting_started_scenario.cpp#L235) (`StartCrawler`) +- [Start a job run](glue_getting_started_scenario.cpp#L394) (`StartJobRun`) ### Scenarios diff --git a/cpp/example_code/glue/glue_getting_started_scenario.cpp b/cpp/example_code/glue/glue_getting_started_scenario.cpp index 442c34f1041..3466734de89 100644 --- a/cpp/example_code/glue/glue_getting_started_scenario.cpp +++ b/cpp/example_code/glue/glue_getting_started_scenario.cpp @@ -178,7 +178,7 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa // 2. Create a crawler. { -// snippet-start:[cpp.example_code.glue.create_crawler] +// snippet-start:[cpp.example_code.glue.CreateCrawler] Aws::Glue::Model::S3Target s3Target; s3Target.SetPath("s3://crawler-public-us-east-1/flight/2016/csv"); Aws::Glue::Model::CrawlerTargets crawlerTargets; @@ -202,12 +202,12 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa deleteAssets("", CRAWLER_DATABASE_NAME, "", bucketName, clientConfig); return false; } -// snippet-end:[cpp.example_code.glue.create_crawler] +// snippet-end:[cpp.example_code.glue.CreateCrawler] } // 3. Get a crawler. { -// snippet-start:[cpp.example_code.glue.get_crawler] +// snippet-start:[cpp.example_code.glue.GetCrawler] Aws::Glue::Model::GetCrawlerRequest request; request.SetName(CRAWLER_NAME); @@ -227,12 +227,12 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa clientConfig); return false; } -// snippet-end:[cpp.example_code.glue.get_crawler] +// snippet-end:[cpp.example_code.glue.GetCrawler] } // 4. Start a crawler. { -// snippet-start:[cpp.example_code.glue.start_crawler] +// snippet-start:[cpp.example_code.glue.StartCrawler] Aws::Glue::Model::StartCrawlerRequest request; request.SetName(CRAWLER_NAME); @@ -294,12 +294,12 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa clientConfig); return false; } -// snippet-end:[cpp.example_code.glue.start_crawler] +// snippet-end:[cpp.example_code.glue.StartCrawler] } // 5. Get a database. { -// snippet-start:[cpp.example_code.glue.get_database] +// snippet-start:[cpp.example_code.glue.GetDatabase] Aws::Glue::Model::GetDatabaseRequest request; request.SetName(CRAWLER_DATABASE_NAME); @@ -318,13 +318,13 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa clientConfig); return false; } -// snippet-end:[cpp.example_code.glue.get_database] +// snippet-end:[cpp.example_code.glue.GetDatabase] } // 6. Get tables. Aws::String tableName; { -// snippet-start:[cpp.example_code.glue.get_tables] +// snippet-start:[cpp.example_code.glue.GetTables] Aws::Glue::Model::GetTablesRequest request; request.SetDatabaseName(CRAWLER_DATABASE_NAME); @@ -356,12 +356,12 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa clientConfig); return false; } -// snippet-end:[cpp.example_code.glue.get_tables] +// snippet-end:[cpp.example_code.glue.GetTables] } // 7. Create a job. { -// snippet-start:[cpp.example_code.glue.create_job] +// snippet-start:[cpp.example_code.glue.CreateJob] Aws::Glue::Model::CreateJobRequest request; request.SetName(JOB_NAME); request.SetRole(roleArn); @@ -386,12 +386,12 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa clientConfig); return false; } -// snippet-end:[cpp.example_code.glue.create_job] +// snippet-end:[cpp.example_code.glue.CreateJob] } // 8. Start a job run. { -// snippet-start:[cpp.example_code.glue.start_job_run] +// snippet-start:[cpp.example_code.glue.StartJobRun] Aws::Glue::Model::StartJobRunRequest request; request.SetJobName(JOB_NAME); @@ -466,7 +466,7 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa clientConfig); return false; } -// snippet-end:[cpp.example_code.glue.start_job_run] +// snippet-end:[cpp.example_code.glue.StartJobRun] } // 9. List the output data stored in the S3 bucket. @@ -521,7 +521,7 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa // 10. List all the jobs. Aws::String jobName; { -// snippet-start:[cpp.example_code.glue.list_jobs] +// snippet-start:[cpp.example_code.glue.ListJobs] Aws::Glue::Model::ListJobsRequest listJobsRequest; Aws::Glue::Model::ListJobsOutcome listRunsOutcome = client.ListJobs( listJobsRequest); @@ -546,13 +546,13 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa << listRunsOutcome.GetError().GetMessage() << std::endl; } -// snippet-end:[cpp.example_code.glue.list_jobs] +// snippet-end:[cpp.example_code.glue.ListJobs] } // 11. Get the job runs for a job. Aws::String jobRunID; if (!jobName.empty()) { -// snippet-start:[cpp.example_code.glue.get_job_runs] +// snippet-start:[cpp.example_code.glue.GetJobRuns] Aws::Glue::Model::GetJobRunsRequest getJobRunsRequest; getJobRunsRequest.SetJobName(jobName); @@ -582,12 +582,12 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa << jobRunsOutcome.GetError().GetMessage() << std::endl; } -// snippet-end:[cpp.example_code.glue.get_job_runs] +// snippet-end:[cpp.example_code.glue.GetJobRuns] } // 12. Get a single job run. if (!jobRunID.empty()) { -// snippet-start:[cpp.example_code.glue.get_job_run] +// snippet-start:[cpp.example_code.glue.GetJobRun] Aws::Glue::Model::GetJobRunRequest jobRunRequest; jobRunRequest.SetJobName(jobName); jobRunRequest.SetRunId(jobRunID); @@ -606,7 +606,7 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa << jobRunOutcome.GetError().GetMessage() << std::endl; } -// snippet-end:[cpp.example_code.glue.get_job_run] +// snippet-end:[cpp.example_code.glue.GetJobRun] } return deleteAssets(CRAWLER_NAME, CRAWLER_DATABASE_NAME, JOB_NAME, bucketName, @@ -631,7 +631,7 @@ bool AwsDoc::Glue::deleteAssets(const Aws::String &crawler, const Aws::String &d // 13. Delete a job. if (!job.empty()) { -// snippet-start:[cpp.example_code.glue.delete_job] +// snippet-start:[cpp.example_code.glue.DeleteJob] Aws::Glue::Model::DeleteJobRequest request; request.SetJobName(job); @@ -646,12 +646,12 @@ bool AwsDoc::Glue::deleteAssets(const Aws::String &crawler, const Aws::String &d << std::endl; result = false; } -// snippet-end:[cpp.example_code.glue.delete_job] +// snippet-end:[cpp.example_code.glue.DeleteJob] } // 14. Delete a database. if (!database.empty()) { -// snippet-start:[cpp.example_code.glue.delete_database] +// snippet-start:[cpp.example_code.glue.DeleteDatabase] Aws::Glue::Model::DeleteDatabaseRequest request; request.SetName(database); @@ -666,12 +666,12 @@ bool AwsDoc::Glue::deleteAssets(const Aws::String &crawler, const Aws::String &d << std::endl; result = false; } -// snippet-end:[cpp.example_code.glue.delete_database] +// snippet-end:[cpp.example_code.glue.DeleteDatabase] } // 15. Delete a crawler. if (!crawler.empty()) { -// snippet-start:[cpp.example_code.glue.delete_crawler] +// snippet-start:[cpp.example_code.glue.DeleteCrawler] Aws::Glue::Model::DeleteCrawlerRequest request; request.SetName(crawler); @@ -685,7 +685,7 @@ bool AwsDoc::Glue::deleteAssets(const Aws::String &crawler, const Aws::String &d << outcome.GetError().GetMessage() << std::endl; result = false; } -// snippet-end:[cpp.example_code.glue.delete_crawler] +// snippet-end:[cpp.example_code.glue.DeleteCrawler] } // 16. Delete the job script and run data from the S3 bucket. diff --git a/cpp/example_code/lambda/README.md b/cpp/example_code/lambda/README.md index 425fe49c06a..911e78f7d65 100644 --- a/cpp/example_code/lambda/README.md +++ b/cpp/example_code/lambda/README.md @@ -46,13 +46,13 @@ Next, for information on code example structures and how to build and run the ex Code excerpts that show you how to call individual service functions. -- [Create a function](get_started_with_functions_scenario.cpp#L605) (`CreateFunction`) -- [Delete a function](get_started_with_functions_scenario.cpp#L605) (`DeleteFunction`) -- [Get a function](get_started_with_functions_scenario.cpp#L605) (`GetFunction`) -- [Invoke a function](get_started_with_functions_scenario.cpp#L605) (`Invoke`) -- [List functions](get_started_with_functions_scenario.cpp#L605) (`ListFunctions`) -- [Update function code](get_started_with_functions_scenario.cpp#L605) (`UpdateFunctionCode`) -- [Update function configuration](get_started_with_functions_scenario.cpp#L605) (`UpdateFunctionConfiguration`) +- [Create a function](get_started_with_functions_scenario.cpp#L172) (`CreateFunction`) +- [Delete a function](get_started_with_functions_scenario.cpp#L843) (`DeleteFunction`) +- [Get a function](get_started_with_functions_scenario.cpp#L488) (`GetFunction`) +- [Invoke a function](get_started_with_functions_scenario.cpp#L538) (`Invoke`) +- [List functions](get_started_with_functions_scenario.cpp#L440) (`ListFunctions`) +- [Update function code](get_started_with_functions_scenario.cpp#L291) (`UpdateFunctionCode`) +- [Update function configuration](get_started_with_functions_scenario.cpp#L342) (`UpdateFunctionConfiguration`) ### Scenarios diff --git a/cpp/example_code/lambda/get_started_with_functions_scenario.cpp b/cpp/example_code/lambda/get_started_with_functions_scenario.cpp index 8b6940942b3..aeea20be9e7 100644 --- a/cpp/example_code/lambda/get_started_with_functions_scenario.cpp +++ b/cpp/example_code/lambda/get_started_with_functions_scenario.cpp @@ -169,7 +169,7 @@ bool AwsDoc::Lambda::getStartedWithFunctionsScenario( // 2. Create a Lambda function. int seconds = 0; do { - // snippet-start:[cpp.example_code.lambda.create_function1] + // snippet-start:[cpp.example_code.lambda.CreateFunction] Aws::Lambda::Model::CreateFunctionRequest request; request.SetFunctionName(LAMBDA_NAME); request.SetDescription(LAMBDA_DESCRIPTION); // Optional. @@ -223,7 +223,7 @@ bool AwsDoc::Lambda::getStartedWithFunctionsScenario( << " seconds elapsed." << std::endl; break; } - // snippet-end:[cpp.example_code.lambda.create_function1] + // snippet-end:[cpp.example_code.lambda.CreateFunction] else if (outcome.GetError().GetErrorType() == Aws::Lambda::LambdaErrors::INVALID_PARAMETER_VALUE && outcome.GetError().GetMessage().find("role") >= 0) { @@ -288,7 +288,7 @@ bool AwsDoc::Lambda::getStartedWithFunctionsScenario( // 4. Update the Lambda function code. { - // snippet-start:[cpp.example_code.lambda.update_function_code] + // snippet-start:[cpp.example_code.lambda.UpdateFunctionCode] Aws::Lambda::Model::UpdateFunctionCodeRequest request; request.SetFunctionName(LAMBDA_NAME); std::ifstream ifstream(CALCULATOR_LAMBDA_CODE.c_str(), @@ -324,7 +324,7 @@ bool AwsDoc::Lambda::getStartedWithFunctionsScenario( << outcome.GetError().GetMessage() << std::endl; } - // snippet-end:[cpp.example_code.lambda.update_function_code] + // snippet-end:[cpp.example_code.lambda.UpdateFunctionCode] } std::cout @@ -339,7 +339,7 @@ bool AwsDoc::Lambda::getStartedWithFunctionsScenario( do { ++seconds; std::this_thread::sleep_for(std::chrono::seconds(1)); - // snippet-start:[cpp.example_code.lambda.update_function_configuration1] + // snippet-start:[cpp.example_code.lambda.UpdateFunctionConfiguration] Aws::Lambda::Model::UpdateFunctionConfigurationRequest request; request.SetFunctionName(LAMBDA_NAME); Aws::Lambda::Model::Environment environment; @@ -354,7 +354,7 @@ bool AwsDoc::Lambda::getStartedWithFunctionsScenario( << std::endl; break; } - // snippet-end:[cpp.example_code.lambda.update_function_configuration1] + // snippet-end:[cpp.example_code.lambda.UpdateFunctionConfiguration] // RESOURCE_IN_USE: function code update not completed. else if (outcome.GetError().GetErrorType() != @@ -437,7 +437,7 @@ bool AwsDoc::Lambda::getStartedWithFunctionsScenario( // 7. List the Lambda functions. - // snippet-start:[cpp.example_code.lambda.list_functions] + // snippet-start:[cpp.example_code.lambda.ListFunctions] std::vector functions; Aws::String marker; @@ -473,7 +473,7 @@ bool AwsDoc::Lambda::getStartedWithFunctionsScenario( << std::endl; } } while (!marker.empty()); - // snippet-end:[cpp.example_code.lambda.list_functions] + // snippet-end:[cpp.example_code.lambda.ListFunctions] // 8. Get a Lambda function. if (!functions.empty()) { @@ -485,7 +485,7 @@ bool AwsDoc::Lambda::getStartedWithFunctionsScenario( Aws::String functionName = functions[functionIndex - 1]; - // snippet-start:[cpp.example_code.lambda.get_function] + // snippet-start:[cpp.example_code.lambda.GetFunction] Aws::Lambda::Model::GetFunctionRequest request; request.SetFunctionName(functionName); @@ -501,7 +501,7 @@ bool AwsDoc::Lambda::getStartedWithFunctionsScenario( << outcome.GetError().GetMessage() << std::endl; } - // snippet-end:[cpp.example_code.lambda.get_function] + // snippet-end:[cpp.example_code.lambda.GetFunction] } std::cout << "The resources will be deleted. Press return to continue, "; @@ -535,7 +535,7 @@ AwsDoc::Lambda::invokeLambdaFunction(const Aws::Utils::Json::JsonValue &jsonPayl * available. */ do { - // snippet-start:[cpp.example_code.lambda.invoke_function1] + // snippet-start:[cpp.example_code.lambda.Invoke] Aws::Lambda::Model::InvokeRequest request; request.SetFunctionName(LAMBDA_NAME); request.SetLogType(logType); @@ -551,7 +551,7 @@ AwsDoc::Lambda::invokeLambdaFunction(const Aws::Utils::Json::JsonValue &jsonPayl result = true; break; } - // snippet-end:[cpp.example_code.lambda.invoke_function1] + // snippet-end:[cpp.example_code.lambda.Invoke] // ACCESS_DENIED: because the role is not available yet. // RESOURCE_CONFLICT: because the Lambda function is being created or updated. @@ -840,7 +840,7 @@ AwsDoc::Lambda::deleteIamRole(const Aws::Client::ClientConfiguration &clientConf \return bool: Successful completion. */ bool AwsDoc::Lambda::deleteLambdaFunction(const Aws::Lambda::LambdaClient &client) { - // snippet-start:[cpp.example_code.lambda.delete_function] + // snippet-start:[cpp.example_code.lambda.DeleteFunction] Aws::Lambda::Model::DeleteFunctionRequest request; request.SetFunctionName(LAMBDA_NAME); @@ -855,7 +855,7 @@ bool AwsDoc::Lambda::deleteLambdaFunction(const Aws::Lambda::LambdaClient &clien << outcome.GetError().GetMessage() << std::endl; } - // snippet-end:[cpp.example_code.lambda.delete_function] + // snippet-end:[cpp.example_code.lambda.DeleteFunction] return outcome.IsSuccess(); }