Skip to content
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

Invalid self signup #145

Merged
merged 15 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ Sync run history の Status / Summary に Completed が表示されれば完了
画像生成のユースケースをご利用になる際は、Stability AI の Stable Diffusion XL モデルを有効化する必要があります。[Model access 画面](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess) を開き、「Edit」 → 「Stable Diffusion XL にチェック」 → 「Save changes」 と操作していただいて、バージニア北部リージョンにて Amazon Bedrock (基盤モデル: Stable Diffusion XL) を利用できる状態にしてください。なお、画像生成に関しては Stable Diffusion XL を有効化していない場合でもユースケースとして画面に表示されるため、注意してください。モデルを有効にしていない状態で実行するとエラーになります。

## その他のドキュメント
- モデル・リージョンの切り替え
- デプロイのオプション
- [Amazon Bedrock の違うモデル・リージョンを利用したい場合](/docs/BEDROCK.md)
- [Amazon SageMaker を利用したい場合](/docs/SAGEMAKER.md)
- [セキュリティ関連](/docs/SECURITY.md)
- 開発
- [ローカル開発環境構築手順](/docs/DEVELOPMENT.md)
- [ユースケースの追加方法 (ブログ: Amazon Bedrock で Interpreter を開発!)](https://aws.amazon.com/jp/builders-flash/202311/bedrock-interpreter/#04)
Expand Down
2 changes: 1 addition & 1 deletion docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## ローカル環境構築手順

開発者用にローカル環境を構築する手順を説明します。なお、ローカル環境を構築する場合も、前述した AWS へのデプロイは完了している必要があります
開発者用にローカル環境を構築する手順を説明します。なお、ローカル環境を構築する場合も、[AWS へのデプロイ](/README.md#デプロイ)は完了している必要があります

### Unix 系コマンドが使えるユーザー (Linux, MacOS 等)

Expand Down
10 changes: 10 additions & 0 deletions docs/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## セルフサインアップを無効化する

このソリューションはデフォルトでセルフサインアップが有効化してあります。セルフサインアップを無効にするには、[cdk.json](./packages/cdk/cdk.json)を開き、`selfSignUpEnabled` を `false` に切り替えてから再デプロイしてください。

```json
"context": {
"ragEnabled": false,
"selfSignUpEnabled": true, // true -> false で無効化
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
```
1 change: 1 addition & 0 deletions packages/cdk/cdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"context": {
"ragEnabled": false,
"selfSignUpEnabled": true,
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
Expand Down
8 changes: 6 additions & 2 deletions packages/cdk/lib/construct/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ import {
} from '@aws-cdk/aws-cognito-identitypool-alpha';
import { Construct } from 'constructs';

export interface AuthProps {
selfSignUpEnabled: boolean;
}

export class Auth extends Construct {
readonly userPool: UserPool;
readonly client: UserPoolClient;
readonly idPool: IdentityPool;

constructor(scope: Construct, id: string) {
constructor(scope: Construct, id: string, props: AuthProps) {
super(scope, id);

const userPool = new UserPool(this, 'UserPool', {
selfSignUpEnabled: true,
selfSignUpEnabled: props.selfSignUpEnabled,
signInAliases: {
username: false,
email: true,
Expand Down
2 changes: 2 additions & 0 deletions packages/cdk/lib/construct/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface WebProps {
idPoolId: string;
predictStreamFunctionArn: string;
ragEnabled: boolean;
selfSignUpEnabled: boolean;
}

export class Web extends Construct {
Expand Down Expand Up @@ -76,6 +77,7 @@ export class Web extends Construct {
VITE_APP_IDENTITY_POOL_ID: props.idPoolId,
VITE_APP_PREDICT_STREAM_FUNCTION_ARN: props.predictStreamFunctionArn,
VITE_APP_RAG_ENABLED: props.ragEnabled.toString(),
VITE_APP_SELF_SIGN_UP_ENABLED: props.selfSignUpEnabled.toString(),
},
});

Expand Down
11 changes: 10 additions & 1 deletion packages/cdk/lib/generative-ai-use-cases-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ export class GenerativeAiUseCasesStack extends Stack {
process.env.overrideWarningsEnabled = 'false';

const ragEnabled: boolean = this.node.tryGetContext('ragEnabled') || false;
const selfSignUpEnabled: boolean =
this.node.tryGetContext('selfSignUpEnabled') || false;
Copy link
Contributor

Choose a reason for hiding this comment

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

cdk context のデフォルト値に合わせたいので true でお願いします!


const auth = new Auth(this, 'Auth');
const auth = new Auth(this, 'Auth',{
selfSignUpEnabled
});
const database = new Database(this, 'Database');
const api = new Api(this, 'API', {
userPool: auth.userPool,
Expand All @@ -25,6 +29,7 @@ export class GenerativeAiUseCasesStack extends Stack {
idPoolId: auth.idPool.identityPoolId,
predictStreamFunctionArn: api.predictStreamFunction.functionArn,
ragEnabled,
selfSignUpEnabled,
});

if (ragEnabled) {
Expand Down Expand Up @@ -66,5 +71,9 @@ export class GenerativeAiUseCasesStack extends Stack {
new CfnOutput(this, 'RagEnabled', {
value: ragEnabled.toString(),
});

new CfnOutput(this, 'SelfSignUpEnabled', {
value: selfSignUpEnabled.toString(),
});
}
}
3 changes: 3 additions & 0 deletions packages/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import useDrawer from './hooks/useDrawer';
import useConversation from './hooks/useConversation';

const ragEnabled: boolean = import.meta.env.VITE_APP_RAG_ENABLED === 'true';
const selfSignUpEnabled: boolean =
import.meta.env.VITE_APP_SELF_SIGN_UP_ENABLED === 'true';

const items: ItemProps[] = [
{
Expand Down Expand Up @@ -132,6 +134,7 @@ const App: React.FC = () => {

return (
<Authenticator
hideSignUp={!selfSignUpEnabled}
components={{
Header: () => (
<div className="text-aws-font-color mb-5 mt-10 flex justify-center text-3xl">
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Item: React.FC<ItemProps> = (props) => {
}, []);
return (
<Link
className={`hover:bg-aws-sky flex h-8 mt-0.5 items-center rounded p-2 ${
className={`hover:bg-aws-sky mt-0.5 flex h-8 items-center rounded p-2 ${
location.pathname === props.to && 'bg-aws-sky'
} ${props.className}`}
to={props.to}
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface ImportMetaEnv {
readonly VITE_APP_IDENTITY_POOL_ID: string;
readonly VITE_APP_PREDICT_STREAM_FUNCTION_ARN: string;
readonly VITE_APP_RAG_ENABLED: string;
readonly VITE_APP_SELF_SIGN_UP_ENABLED: string;
}

interface ImportMeta {
Expand Down
1 change: 1 addition & 0 deletions setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export VITE_APP_USER_POOL_CLIENT_ID=`stack_output 'UserPoolClientId'`
export VITE_APP_IDENTITY_POOL_ID=`stack_output 'IdPoolId'`
export VITE_APP_PREDICT_STREAM_FUNCTION_ARN=`stack_output PredictStreamFunctionArn`
export VITE_APP_RAG_ENABLED=`stack_output RagEnabled`
export VITE_APP_SELF_SIGN_UP_ENABLED=`stack_output SelfSignUpEnabled`