diff --git a/.github/workflows/sync-S3-KB.yml b/.github/workflows/sync-S3-KB.yml new file mode 100644 index 00000000000..1642517cf69 --- /dev/null +++ b/.github/workflows/sync-S3-KB.yml @@ -0,0 +1,120 @@ +name: syncS3andKB +on: + push: + branches: ["main"] + workflow_dispatch: + inputs: + sdk_name: + description: 'SDK Name' + required: true + default: 'python' + type: choice + options: + - javascriptv3 + - dotnetv4 + - javav2 + - rustv1 + - gov2 + - swift + - python + - ruby + - php + - cpp + - kotlin + +permissions: + id-token: write + +jobs: + run_job_with_aws: + runs-on: ubuntu-latest + env: + sdk_name: ${{ github.event.inputs.sdk_name || 'python' }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v5 + with: + role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }} # once merged, update trust policy of the role to point to main branch + aws-region: us-west-2 + + - name: Set SDK and language mapping for S3 + run: | + if [ "$sdk_name" == "javascriptv3" ]; then + echo "S3_LANGUAGE=javascript" >> $GITHUB_ENV + elif [ "$sdk_name" == "dotnetv4" ]; then + echo "S3_LANGUAGE=dotnet" >> $GITHUB_ENV + elif [ "$sdk_name" == "javav2" ]; then + echo "S3_LANGUAGE=java" >> $GITHUB_ENV + elif [ "$sdk_name" == "rustv1" ]; then + echo "S3_LANGUAGE=rust" >> $GITHUB_ENV + elif [ "$sdk_name" == "gov2" ]; then + echo "S3_LANGUAGE=go" >> $GITHUB_ENV + else + echo "S3_LANGUAGE=$sdk_name" >> $GITHUB_ENV + fi + + - name: Extract and copy premium examples in temp. dir. + run: | + MARKDOWN_FILE="./$sdk_name/premium-ex.md" + + if [ ! -f "$MARKDOWN_FILE" ]; then + echo "Premium examples file not found: $MARKDOWN_FILE" + exit 1 + fi + + extract_paths() { + local level="$1" + local section_found=false + + while IFS= read -r line; do + if [[ "$line" =~ ^##[[:space:]]*${level}:[[:space:]]*$ ]]; then + section_found=true + continue + elif [[ "$line" =~ ^##[[:space:]] ]] && [ "$section_found" = true ]; then + break + elif [ "$section_found" = true ] && [[ "$line" =~ ^/ ]]; then + echo "$line" + fi + done < "$MARKDOWN_FILE" + } + + for level in "basics" "feature-scenario" "complex-feature-scenario"; do + paths=$(extract_paths "$level") + + if [ -n "$paths" ]; then + mkdir -p "./extracted_snippets/$level" + + while IFS= read -r path; do + if [ -n "$path" ]; then + source_path="./$sdk_name$path" + if [ -e "$source_path" ]; then + cp -r "$source_path" "./extracted_snippets/$level/" + fi + fi + done <<< "$paths" + fi + done + + - name: Upload/Sync to S3 + run: | + for level in "basics" "feature-scenario" "complex-feature-scenario"; do + if [ -d "./extracted_snippets/$level" ]; then + aws s3 sync "./extracted_snippets/$level/" "s3://$S3_LANGUAGE-premium-bucket/$level/" --delete + echo "Uploaded $level examples to S3" + fi + done + + - name: Sync Knowledge Base Data Source + run: | + aws lambda invoke \ + --function-name KB_Updater \ + --payload "{\"language\":\"$S3_LANGUAGE\",\"region\":\"us-west-2\"}" \ + --cli-binary-format raw-in-base64-out \ + response.json + + echo "Knowledge Base sync initiated" + cat response.json diff --git a/cpp/premium-ex.md b/cpp/premium-ex.md new file mode 100644 index 00000000000..942cac40e28 --- /dev/null +++ b/cpp/premium-ex.md @@ -0,0 +1,10 @@ +//Add paths for premium examples here which will be consumed by workflow to update KB with quality code + +## basics: +/example_code/s3/s3_getting_started_scenario.cpp + +## feature-scenario: +/example_code/medical-imaging/imaging_set_and_frames_workflow + +## complex-feature-scenario: +/example_code/s3/s3_object_integrity_workflow diff --git a/dotnetv4/premium-ex.md b/dotnetv4/premium-ex.md new file mode 100644 index 00000000000..0d26ae16854 --- /dev/null +++ b/dotnetv4/premium-ex.md @@ -0,0 +1,11 @@ +//Add paths for premium examples here which will be consumed by workflow to update KB with quality code +//Don't forget to add new line at the end of this file + +## basics: +/ControlTower + +## feature-scenario: +/CloudWatch/Scenarios + +## complex-feature-scenario: +/S3/Scenarios/S3_CreatePresignedPost diff --git a/gov2/premium-ex.md b/gov2/premium-ex.md new file mode 100644 index 00000000000..42a552bc35a --- /dev/null +++ b/gov2/premium-ex.md @@ -0,0 +1,11 @@ +//Add paths for premium examples here which will be consumed by workflow to update KB with quality code +//Don't forget to add new line at the end of this file + +## basics: +/s3/actions/bucket_basics.go + +## feature-scenario: +/s3/actions/bucket_basics.go + +## complex-feature-scenario: +/dynamodb/scenarios/scenario_movie_table.go diff --git a/javascriptv3/premium-ex.md b/javascriptv3/premium-ex.md new file mode 100644 index 00000000000..78ff7a0ca6b --- /dev/null +++ b/javascriptv3/premium-ex.md @@ -0,0 +1,11 @@ +//Add paths for premium examples here which will be consumed by workflow to update KB with quality code +//Don't forget to add new line at the end of this file + +## basics: +/example_code/s3/scenarios/basic.js + +## feature-scenario: +/example_code/s3/scenarios/object-locking + +## complex-feature-scenario: +/example_code/bedrock-runtime/scenarios/converse_tool_scenario/converse-tool-scenario.js diff --git a/javav2/premium-ex.md b/javav2/premium-ex.md new file mode 100644 index 00000000000..826faf47413 --- /dev/null +++ b/javav2/premium-ex.md @@ -0,0 +1,11 @@ +//Add paths for premium examples here which will be consumed by workflow to update KB with quality code +//Don't forget to add new line at the end of this file + +## basics: +/example_code/iotsitewise/src/main/java/com/example/iotsitewise/HelloSitewise.java + +## feature-scenario: +/example_code/s3/src/main/java/com/example/s3/lockscenario + +## complex-feature-scenario: +/example_code/bedrock-runtime/src/main/java/com/example/bedrockruntime/scenario diff --git a/kotlin/premium-ex.md b/kotlin/premium-ex.md new file mode 100644 index 00000000000..2c578d531cf --- /dev/null +++ b/kotlin/premium-ex.md @@ -0,0 +1,11 @@ +//Add paths for premium examples here which will be consumed by workflow to update KB with quality code +//Don't forget to add new line at the end of this file + +## basics: +/services/iotfleetwise + +## feature-scenario: +/services/dynamodb/src/main/kotlin/com/kotlin/dynamodb/scenario/ScenarioPartiQ.kt + +## complex-feature-scenario: +/services/dynamodb/src/main/kotlin/com/kotlin/dynamodb/scenario/ScenarioPartiQLBatch.kt diff --git a/php/premium-ex.md b/php/premium-ex.md new file mode 100644 index 00000000000..4ba65c38ca0 --- /dev/null +++ b/php/premium-ex.md @@ -0,0 +1,11 @@ +//Add paths for premium examples here which will be consumed by workflow to update KB with quality code +//Don't forget to add new line at the end of this file + +## basics: +/example_code/s3/GettingStartedWithS3.php + +## feature-scenario: + + +## complex-feature-scenario: +/applications/photo_asset_manager diff --git a/python/premium-ex.md b/python/premium-ex.md new file mode 100644 index 00000000000..cc724b5316d --- /dev/null +++ b/python/premium-ex.md @@ -0,0 +1,11 @@ +//Add paths for premium examples here which will be consumed by workflow to update KB with quality code +//Don't forget to add new line at the end of this file + +## basics: +/example_code/controltower + +## feature-scenario: +/example_code/s3/scenarios/conditional_requests + +## complex-feature-scenario: +/example_code/medical-imaging/imaging_set_and_frames_workflow diff --git a/ruby/premium-ex.md b/ruby/premium-ex.md new file mode 100644 index 00000000000..e97eb3af62d --- /dev/null +++ b/ruby/premium-ex.md @@ -0,0 +1,11 @@ +//Add paths for premium examples here which will be consumed by workflow to update KB with quality code +//Don't forget to add new line at the end of this file + +## basics: +/example_code/s3/scenario_getting_started.rb + +## feature-scenario: + + +## complex-feature-scenario: + diff --git a/rustv1/premium-ex.md b/rustv1/premium-ex.md new file mode 100644 index 00000000000..4a31da52195 --- /dev/null +++ b/rustv1/premium-ex.md @@ -0,0 +1,11 @@ +//Add paths for premium examples here which will be consumed by workflow to update KB with quality code +//Don't forget to add new line at the end of this file + +## basics: +/examples/lambda + +## feature-scenario: +/examples/ec2 + +## complex-feature-scenario: + diff --git a/swift/premium-ex.md b/swift/premium-ex.md new file mode 100644 index 00000000000..6d8904d5f13 --- /dev/null +++ b/swift/premium-ex.md @@ -0,0 +1,11 @@ +//Add paths for premium examples here which will be consumed by workflow to update KB with quality code +//Don't forget to add new line at the end of this file + +## basics: +/example_code/cognito-identity-provider/scenario + +## feature-scenario: +/example_code/bedrock-runtime/models/amazon-nova/amazon-nova-reel + +## complex-feature-scenario: +/example_code/sqs/scenario