Skip to content

別アカウントの Bedrock を利用するためのクロスアカウント設定を追加 #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2024

Conversation

tomachi1201
Copy link
Contributor

目的

Bedrock サービスのみ、別の AWS アカウントを指定して構成する

利用条件

  • Bedrock 用 AWS アカウント で IAM Role を手動で作成しておく
  • 作成した IAM Role を cdk.json に手動で書く

修正内容

  • packages/cdk/cdk.json

    • roleArn と sessionName を追加した。
    • roleArn に "arn:aws:iam::アカウントID:role/ロール名" を指定することにより、別の AWS アカウント上の Bedrock サービスを利用できるようになる。
    • sessionName にはデフォルト値を設定済みである。
  • packages/cdk/lib/construct/api.ts

    • 上記を Lambda 環境変数に設定する
    • roleArn が指定されている場合に AssumeRole 用のポリシーを設定
  • packages/cdk/lambda/utils/bedrockApi.ts

    • roleArn が設定されている場合に AssumeRole する

動作確認

  • cdk デプロイできることを確認した
  • ユースケース一覧が動作することを確認した
  • roleArn 設定時に Bedrock アカウントのみ、トークン数などが増えていることを CloudWatch Metrics から確認した
  • roleArn 非設定時に アプリケーションデプロイ用アカウントのみ、トークン数などが増えていることを CloudWatch Metrics から確認した

Copy link
Contributor

@tbrand tbrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いくつかコメントさせていただきました!

別のAWSアカウントでRoleを作成して cdk.json に設定するまでの手順を https://github.com/aws-samples/generative-ai-use-cases-jp/blob/main/docs/DEPLOY_OPTION.md に追加をお願いします!:pray: おそらく利用頻度としては低いオプションになると思うので、追加位置は最下部で問題ありません!また、手動で作成する手順を説明するにあたって、スクリーンショットなどは必要ありません!追加後に、DEPLOY_OPTION.md の他の項目と同様 README.md にアンカーリンクを追加してください!

また、念のためですが、ルートディレクトリにて npm run lint を実行していただけますでしょうか?:pray: (すでに実行されていたらすいません!)

@tomachi1201
Copy link
Contributor Author

別のAWSアカウントでRoleを作成して cdk.json に設定するまでの手順を https://github.com/aws-samples/generative-ai-use-cases-jp/blob/main/docs/DEPLOY_OPTION.md に追加をお願いします!:pray: おそらく利用頻度としては低いオプションになると思うので、追加位置は最下部で問題ありません!また、手動で作成する手順を説明するにあたって、スクリーンショットなどは必要ありません!追加後に、DEPLOY_OPTION.md の他の項目と同様 README.md にアンカーリンクを追加してください!
→対応しましたのでご確認頂ければと思います。

また、念のためですが、ルートディレクトリにて npm run lint を実行していただけますでしょうか?:pray: (すでに実行されていたらすいません!)
→すみません、こちら実行していなかったので実行致しました。

コメント頂いた内容を修正したものをアップしておりますのでご確認をお願い致します。

@@ -17,7 +17,7 @@
]
},
"context": {
"ragEnabled": false,
"ragEnabled": true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要なコミットが入っています!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

すみません、修正します!

@@ -48,6 +48,7 @@
"anonymousUsageTracking": true,
"recognizeFileEnabled": false,
"vpcId": null,
"crossAccountBedrockRoleArn": "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

今までの設定項目と統一して、利用しない場合のデフォルト値を null にしていただいても良いでしょうか?

Copy link
Contributor Author

@tomachi1201 tomachi1201 Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null に変更後に再デプロイしたところ、以下のエラーが出力されたのですが、Lambda の環境変数には null は設定できないと理解しました。(認識齟齬ございましたらご指摘ください)

nerativeAiUseCasesStack failed: Error [ValidationError]: [/Resources/APIPredict09E4E4FF/Type/Environment/Variables/CROSS_ACCOUNT_BEDROCK_ROLE_ARN] 'null' values are not allowed in templates

そのため、空文字列 "" をデフォルト値とできればと思いますが如何でしょうか。
もしくは、null 値の場合、環境変数自体を設定しないように修正した方が良いでしょうか。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

すみません改めて確認したら全て null というわけではなく空文字もちょくちょく使っていたので、空文字で大丈夫です!:pray:

Copy link
Contributor

@tbrand tbrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!ありがとうございます!

@tbrand tbrand merged commit 1209cad into aws-samples:main Apr 12, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants