Created
March 17, 2026 16:40
-
-
Save gciampa/31b838d7fc0f2d6ab59603f486bc9872 to your computer and use it in GitHub Desktop.
Launch claude with aws bedrock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| claude-aws() { | |
| local cache_file="/tmp/bedrock_models_cache" | |
| local cache_ttl=86400 | |
| local selected_model_id | |
| local selected_profile | |
| local current_time=$(date +%s) | |
| # 1. Select AWS Profile via fzf FIRST | |
| # We need this now so it can be used for the cache refresh if needed | |
| selected_profile=$(aws-vault list --profiles | fzf --height 20% --border --header "Select AWS Profile") | |
| if [[ -z "$selected_profile" ]]; then | |
| echo "No profile selected. Exiting." | |
| return 1 | |
| fi | |
| # 2. Manual Cache Refresh Flag | |
| if [[ "$1" == "--refresh" ]]; then | |
| rm -f "$cache_file" | |
| shift | |
| fi | |
| # 3. Handle Bedrock Model Caching using the SELECTED profile | |
| if [[ ! -f "$cache_file" ]] || [[ $((current_time - $(date -r "$cache_file" +%s))) -gt $cache_ttl ]]; then | |
| echo "Refreshing Bedrock model cache using $selected_profile..." >&2 | |
| # Replaced hardcoded 'oam-next-dev-admin' with '$selected_profile' | |
| aws-vault exec "$selected_profile" -- aws bedrock list-foundation-models \ | |
| --by-provider Anthropic \ | |
| --query 'modelSummaries[?modelLifecycle.status==`ACTIVE`].[modelId, modelName]' \ | |
| --output text | sort -k2 > "$cache_file" 2>/dev/null | |
| fi | |
| # 4. Select Bedrock Model via fzf | |
| selected_model_id=$(cat "$cache_file" | fzf --height 40% --border --header "Select Model (Profile: $selected_profile)" \ | |
| --delimiter '\t' --with-nth 2.. \ | |
| | awk '{print $1}') | |
| if [[ -z "$selected_model_id" ]]; then | |
| echo "No model selected. Exiting." | |
| return 1 | |
| fi | |
| # 5. Execute | |
| echo "Launching Claude ($selected_model_id) using profile: $selected_profile" | |
| ANTHROPIC_MODEL="$selected_model_id" \ | |
| CLAUDE_CODE_USE_BEDROCK=1 \ | |
| AWS_REGION="${AWS_REGION:-us-east-1}" \ | |
| aws-vault exec "$selected_profile" -- claude "$@" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment