Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .github/workflows/sync-S3-KB.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions cpp/premium-ex.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions dotnetv4/premium-ex.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions gov2/premium-ex.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions javascriptv3/premium-ex.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions javav2/premium-ex.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions kotlin/premium-ex.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions php/premium-ex.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions python/premium-ex.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions ruby/premium-ex.md
Original file line number Diff line number Diff line change
@@ -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:

11 changes: 11 additions & 0 deletions rustv1/premium-ex.md
Original file line number Diff line number Diff line change
@@ -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:

11 changes: 11 additions & 0 deletions swift/premium-ex.md
Original file line number Diff line number Diff line change
@@ -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
Loading