├── .gitignore
├── .npmignore
├── .prettierignore
├── .prettierrc.json
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── DEPLOY.md
├── DEPLOY_ja.md
├── LICENSE
├── README.md
├── README_ja.md
├── bin
├── cdk_test.ts
└── whats-new-summary-notifier.ts
├── cdk.context.json
├── cdk.json
├── doc
├── architecture.png
├── example_en.png
└── example_ja.png
├── eslint.config.mjs
├── lambda
├── notify-to-app
│ ├── index.py
│ └── requirements.txt
└── rss-crawler
│ ├── index.py
│ └── requirements.txt
├── lib
└── whats-new-summary-notifier-stack.ts
├── package-lock.json
├── package.json
└── tsconfig.json
/.gitignore:
--------------------------------------------------------------------------------
1 | *.js
2 | !jest.config.js
3 | *.d.ts
4 | node_modules
5 |
6 | # AWS CDK
7 | cdk.out/
8 | .cdk.staging
9 | .DS_Store
10 |
11 | # Python
12 | __pycache__/
13 | *.py[cod]
14 | *$py.class
15 |
16 | # virtual env
17 | venv/
18 | ENV/
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | *.ts
2 | !*.d.ts
3 |
4 | # CDK asset staging directory
5 | .cdk.staging
6 | cdk.out/
7 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | **/*.json
2 | **/*.md
3 | **/*.txt
4 | **/node_modules
5 | **/dist
6 | **/*.py
7 | **/*.yml
8 |
9 | .gitignore
10 | .npmignore
11 | .prettierignore
12 |
13 | doc
14 |
15 | LICENSE
--------------------------------------------------------------------------------
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 120,
3 | "trailingComma": "es5",
4 | "tabWidth": 2,
5 | "semi": true,
6 | "singleQuote": true,
7 | "bracketSpacing": true,
8 | "bracketSameLine": true,
9 | "arrowParens": "always",
10 | "parser": "typescript"
11 | }
12 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | ## Code of Conduct
2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
4 | opensource-codeofconduct@amazon.com with any additional questions or comments.
5 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Guidelines
2 |
3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
4 | documentation, we greatly value feedback and contributions from our community.
5 |
6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
7 | information to effectively respond to your bug report or contribution.
8 |
9 |
10 | ## Reporting Bugs/Feature Requests
11 |
12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features.
13 |
14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already
15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
16 |
17 | * A reproducible test case or series of steps
18 | * The version of our code being used
19 | * Any modifications you've made relevant to the bug
20 | * Anything unusual about your environment or deployment
21 |
22 |
23 | ## Contributing via Pull Requests
24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
25 |
26 | 1. You are working against the latest source on the *main* branch.
27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
29 |
30 | To send us a pull request, please:
31 |
32 | 1. Fork the repository.
33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34 | 3. Ensure local tests pass.
35 | 4. Commit to your fork using clear commit messages.
36 | 5. Send us a pull request, answering any default questions in the pull request interface.
37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
38 |
39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
41 |
42 |
43 | ## Finding contributions to work on
44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.
45 |
46 |
47 | ## Code of Conduct
48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
50 | opensource-codeofconduct@amazon.com with any additional questions or comments.
51 |
52 |
53 | ## Security issue notifications
54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
55 |
56 |
57 | ## Licensing
58 |
59 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
60 |
--------------------------------------------------------------------------------
/DEPLOY.md:
--------------------------------------------------------------------------------
1 | # Deployment Options
2 | This asset uses the AWS CDK context to configure the settings.
3 |
4 | You can change the settings by modifying the values under the `context` section in the [cdk.json](cdk.json) file. The details of each configuration item are as follows:
5 |
6 | ## Common Settings
7 | * `modelRegion`: The region to use Amazon Bedrock. Enter the region code of the region you want to use from among the regions where Amazon Bedrock is available.
8 | * `modelId`: The model ID of the base model to be used with Amazon Bedrock. It supports Anthropic Claude 3 and earlier versions. Refer to the documentation for the model ID of each model.
9 |
10 | ## summarizers
11 | Configure the prompt for summarizing the input to the generative AI.
12 |
13 | * `outputLanguage`: The language of the model output.
14 | * `persona`: The role (persona) to be given to the model.
15 |
16 | ## notifiers
17 | Configure the delivery settings to the application.
18 |
19 | * `destination`: The name of application to post to. Set either `slack` or `teams` according to the destination.
20 | * `summarizerName`: The name of the summarizer to use for delivery.
21 | * `webhookUrlParameterName`: The name of the AWS Systems Manager Parameter Store parameter that stores the Webhook URL.
22 | * `rssUrl`: The RSS feed URL of the website from which you want to get the latest information. Multiple URLs can be specified.
23 | * `schedule` (optional): The interval for retrieving the RSS feed in CRON format. If this parameter is not specified, the feed will be retrieved at 00 minutes every hour. In the example below, the feed will be retrieved every 15 minutes.
24 |
25 | ```json
26 | ...
27 | "schedule": {
28 | "minute": "0/15",
29 | "hour": "*",
30 | "day": "*",
31 | "month": "*",
32 | "year": "*"
33 | }
34 | ```
35 |
36 | # Preparing the Deployment Environment (AWS Cloud9)
37 | This procedure creates a development environment on AWS with the necessary tools installed.
38 | The environment is built using AWS Cloud9.
39 | For more details on AWS Cloud9, please refer to [What is AWS Cloud9?](https://docs.aws.amazon.com/cloud9/latest/user-guide/welcome.html).
40 |
41 | 1. Open [CloudShell](https://console.aws.amazon.com/cloudshell/home).
42 | 2. Clone this repository.
43 | ```bash
44 | git clone https://github.com/aws-samples/cloud9-setup-for-prototyping
45 | ```
46 | 3. Move to the directory
47 | ```bash
48 | cd cloud9-setup-for-prototyping
49 | ```
50 | 4. Change volume capacities as needed for cost optimization.
51 | ```bash
52 | cat <<< $(jq '.volume_size = 20' params.json ) > params.json
53 | ```
54 | 5. Run the script.
55 | ```bash
56 | ./bin/bootstrap
57 | ```
58 | 6. Move to [Cloud9](https://console.aws.amazon.com/cloud9/home), and click "Open IDE ".
59 |
60 | > [!NOTE]
61 | > The AWS Cloud9 environment created in this procedure will incur pay-per-use EC2 charges based on usage time.
62 | > It is set to automatically stop after 30 minutes of inactivity, but the charges for the instance volume (Amazon EBS) will continue to accrue.
63 | > If you want to minimize charges, please delete the environment after deployment of the asset, following the instructions in [Deleting an environment in AWS Cloud9](https://docs.aws.amazon.com/cloud9/latest/user-guide/delete-environment.html).
--------------------------------------------------------------------------------
/DEPLOY_ja.md:
--------------------------------------------------------------------------------
1 | # デプロイオプション
2 | 本アセットは、AWS CDK の context で設定を変更します。
3 |
4 | [cdk.json](cdk.json) の `context` 以下の値を変更することで設定します。各設定項目についての説明は下記の通りです。
5 |
6 | ## 共通設定
7 | * `modelRegion`: Amazon Bedrock を利用するリージョン。Amazon Bedrock を利用可能なリージョンの中から、利用したいリージョンのリージョンコードを入力してください。
8 | * `modelId`: Amazon Bedrock で利用する基盤モデルの model ID。Anthropic Claude 3 およびそれ以前のバージョンに対応をしています。各モデルの model ID はドキュメントを参照ください。
9 |
10 | ## summarizers
11 | 生成 AI に入力する要約用プロンプトの設定を行います。
12 |
13 | * `outputLanguage`: モデル出力の言語。
14 | * `persona`: モデルに与える役割 (ペルソナ)。
15 |
16 | ## notifiers
17 | アプリケーションへの配信設定を行います。
18 |
19 | * `destination`: 投稿先のアプリケーション名。`slack` か `teams` のいずれかを設定してください。
20 | * `summarizerName`: 配信に使用する summarizer の名前。
21 | * `webhookUrlParameterName`: Webhook URL を格納している AWS Systems Manager Parameter Store のパラメータ名。
22 | * `rssUrl`: 最新情報を取得したい Web サイトの RSS フィード URL。URL は複数指定する事が可能です。
23 | * `schedule` (オプション): CRON 形式の RSS フィード取得間隔。本パラメータの指定がない場合は、毎時 00 分にフィードを取得します。下記の例の場合は、15 分に一度フィード取得が行われます。
24 |
25 | ```json
26 | ...
27 | "schedule": {
28 | "minute": "0/15",
29 | "hour": "*",
30 | "day": "*",
31 | "month": "*",
32 | "year": "*"
33 | }
34 | ```
35 |
36 | # 操作環境の準備 (AWS Cloud9)
37 | 本手順では、AWS 上に必要なツールがインストールされた開発環境を作成します。環境構築には、AWS Cloud9 を使用します。
38 | AWS Cloud9 についての詳細は、[AWS Cloud9 とは?](https://docs.aws.amazon.com/ja_jp/cloud9/latest/user-guide/welcome.html)を参照してください。
39 |
40 | 1. [CloudShell](https://console.aws.amazon.com/cloudshell/home) を開いてください。
41 | 2. 以下のコマンドでリポジトリをクローンしてください。
42 | ```bash
43 | git clone https://github.com/aws-samples/cloud9-setup-for-prototyping
44 | ```
45 | 3. ディレクトリに移動してください。
46 | ```bash
47 | cd cloud9-setup-for-prototyping
48 | ```
49 | 4. コスト最適化のため必要に応じてボリュームの容量を変更します。
50 | ```bash
51 | cat <<< $(jq '.volume_size = 20' params.json ) > params.json
52 | ```
53 | 5. スクリプトを実行してください。
54 | ```bash
55 | ./bin/bootstrap
56 | ```
57 | 1. [Cloud9](https://console.aws.amazon.com/cloud9/home) に移動し、"Open IDE" をクリックします。
58 |
59 | > [!NOTE]
60 | > 本手順で作成した AWS Cloud9 環境は、利用時間に応じて EC2 料金が従量課金で発生します。
61 | > 30 分未操作の場合は自動停止する設定になっていますが、インスタンスボリューム (Amazon EBS) の課金は継続して発生するため、
62 | > 料金発生を最小限にしたい場合は、アセットのデプロイ後に [AWS Cloud9 で環境を削除する](https://docs.aws.amazon.com/ja_jp/cloud9/latest/user-guide/delete-environment.html)に従って環境の削除を行ってください。
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT No Attribution
2 |
3 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so.
10 |
11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
13 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
15 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 |
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Whats New Summary Notifier
2 |
3 | **[日本語はこちら](README_ja.md)**
4 |
5 | **Whats New Summary Notifier** is a sample implementation of a generative AI application that summarizes the content of AWS What's New and other web articles in multiple languages when there is an update, and delivers the summary to Slack or Microsoft Teams.
6 |
7 |
8 |
9 |
10 |
11 | ## Architecture
12 |
13 | This stack create following architecture.
14 |
15 | 
16 |
17 | ## Prerequisites
18 | - An environment where you can execute Unix commands (Mac, Linux, ...)
19 | - If you don't have such an environment, you can also use AWS Cloud9. Please refer to [Preparing the Operating Environment (AWS Cloud9)](DEPLOY.md).
20 | - aws-cdk
21 | - You can install it with `npm install -g aws-cdk`. For more details, please refer to the [AWS documentation](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html).
22 | - Docker
23 | - Docker is required to build Lambda functions using the [`aws-lambda-python-alpha`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-lambda-python-alpha-readme.html) construct. Please refer to the [Docker documentation](https://docs.docker.com/engine/install/) for more information.
24 |
25 | ## Deployment Steps
26 | > [!IMPORTANT]
27 | > This repository is set up to use the Anthropic Claude 3 Sonnet model in the US East (N. Virginia) region (us-east-1) by default. Please open the [Model access screen (us-east-1)](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess), check the Anthropic Claude 3 Sonnet option, and click Save changes.
28 |
29 | ### Create Webhook URL
30 | Create the Webhook URL required for the notifications.
31 |
32 | #### For Microsoft Teams
33 | First open the `cdk.json` file and change the `destination` value in the `context`-`notifiers` section from `slack` to `teams`. Then, refer to [this documentation](https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=newteams%2Cdotnet) to create the Webhook URL.
34 |
35 | #### For Slack
36 | Refer to [this documentation](https://slack.com/help/articles/17542172840595-Build-a-workflow--Create-a-workflow-in-Slack) to create the Webhook URL. Select "Add a Variable" and create the following 5 variables, all with the Text data type:
37 |
38 | * `rss_time`: The time the article was posted
39 | * `rss_link`: The URL of the article
40 | * `rss_title`: The title of the article
41 | * `summary`: A summary of the article
42 | * `detail`: A bulleted description of the article
43 |
44 | ### Create AWS Systems Manager Parameter Store
45 |
46 | Use Parameter Store to securely store the notification URL.
47 |
48 | #### Put into Parameter Store (AWS CLI)
49 |
50 | ```
51 | aws ssm put-parameter \
52 | --name "/WhatsNew/URL" \
53 | --type "SecureString" \
54 | --value ""
55 | ```
56 |
57 | ### Changing the Language Setting (Optional)
58 | This asset is set up to output summaries in Japanese (日本語) by default. If you want to generate output in other languages such as English, open the `cdk.json` file and change the `summarizerName` value inside the `notifiers` object within the `context` section from `AwsSolutionsArchitectJapanese` to `AwsSolutionsArchitectEnglish` or another language. For more information on other configuration options, please refer to the [Deployment Guide](DEPLOY.md). For more information on other configuration options, please refer to the [Deployment Guide](DEPLOY.md).
59 |
60 | ### Execute the deployment
61 | **Initialize**
62 |
63 | If you haven't used CDK in this region before, run the following command:
64 |
65 | ```
66 | cdk bootstrap
67 | ```
68 |
69 | **Verify no errors**
70 | ```
71 | cdk synth
72 | ```
73 |
74 | **Execute Deployment**
75 |
76 | ```
77 | cdk deploy
78 | ```
79 |
80 | ## Delete Stack
81 | If no longer needed, run the following command to delete the stack:
82 | ```
83 | cdk destroy
84 | ```
85 | By default, some resources such as the Amazon DynamoDB table are set to not be deleted.
86 | If you need to completely delete everything, you will need to access the remaining resources and manually delete them.
87 |
88 | ## Third Party Services
89 | This code interacts with Slack or Microsoft Teams which has terms published at [Terms Page (Slack)](https://slack.com/main-services-agreement) / [Terms Page (Microsoft 365)](https://www.microsoft.com/en/servicesagreement), and pricing described at [Pricing Page (Slack)](https://slack.com/pricing) / [Pricing Page (Microsoft 365)](https://www.microsoft.com/en-us/microsoft-365/business/compare-all-microsoft-365-business-products?&activetab=tab:primaryr2). You should be familiar with the pricing and confirm that your use case complies with the terms before proceeding.
--------------------------------------------------------------------------------
/README_ja.md:
--------------------------------------------------------------------------------
1 | # Whats New Summary Notifier
2 |
3 | **Whats New Summary Notifier** は、AWS 最新情報 (What's New) などのウェブ記事に更新があった際に記事内容を Amazon Bedrock で要約し、Slack や Microsoft Teams への配信を行う生成 AI アプリケーションのサンプル実装です。
4 |
5 |
6 |
7 |
8 |
9 | ## アーキテクチャ
10 |
11 | 
12 |
13 | ## 前提条件
14 | - Unix コマンドを実行できる環境 (Mac、Linux、...)
15 | - そのような環境がない場合は、AWS Cloud9 を使用することも可能です。[操作環境の準備 (AWS Cloud9)](DEPLOY_ja.md) をご参照ください。
16 | - aws-cdk
17 | - `npm install -g aws-cdk` でインストール可能です。詳しくは [AWS ドキュメント](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html)を参考にしてください。
18 | - Docker
19 | - [`aws-lambda-python-alpha`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-lambda-python-alpha-readme.html) コンストラクトで Lambda をビルドするために Docker が必要です。詳しくは [Docker ドキュメント](https://docs.docker.com/engine/install/)を参考にしてください。
20 |
21 | ## デプロイ手順
22 | > [!IMPORTANT]
23 | > このリポジトリでは、デフォルトで米国東部 (バージニア北部) リージョン (us-east-1) の Anthropic Claude 3 Sonnet モデルを利用する設定になっています。[Model access 画面 (us-east-1)](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess)を開き、Anthropic Claude 3 Sonnet にチェックして Save changes してください。
24 |
25 | ### Webhook URL の取得
26 | 通知に必要となる Webhook URL の払い出しを行います。
27 |
28 | #### Microsoft Teams の場合
29 |
30 | まず `cdk.json` を開き、`context` の`notifiers`内、`destination` を `slack` から `teams` に書き換えてください。次に、[こちらのドキュメント](https://learn.microsoft.com/ja-jp/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=newteams%2Cdotnet)を参考にして Webhook URL を取得してください。
31 |
32 | #### Slack の場合
33 | [こちらのドキュメント](https://slack.com/intl/ja-jp/help/articles/360041352714-%E3%83%AF%E3%83%BC%E3%82%AF%E3%83%95%E3%83%AD%E3%83%BC%E3%82%92%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B---Slack-%E5%A4%96%E9%83%A8%E3%81%A7%E9%96%8B%E5%A7%8B%E3%81%95%E3%82%8C%E3%82%8B%E3%83%AF%E3%83%BC%E3%82%AF%E3%83%95%E3%83%AD%E3%83%BC%E3%82%92%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B)を参考にして Webhook URL を取得してください。「変数を追加する」を選び、次の 5 つの変数をすべてテキストデータタイプで作成します。
34 |
35 | * `rss_time`: 記事の投稿時間
36 | * `rss_link`: 記事の URL
37 | * `rss_title`: 記事のタイトル
38 | * `summary`: 記事の要約
39 | * `detail`: 記事の箇条書き説明
40 |
41 | ### AWS Systems Manager Parameter Store を作成
42 |
43 | Parameter Store を使って 通知用の URL をセキュアに格納します。
44 |
45 | #### パラメータストア登録 (AWS CLI)
46 |
47 | ```
48 | aws ssm put-parameter \
49 | --name "/WhatsNew/URL" \
50 | --type "SecureString" \
51 | --value ""
52 | ```
53 |
54 | ### 言語設定の変更 (オプション)
55 | このアセットはデフォルトで日本語の要約を出力するように設定されています。英語等の他言語の出力を行う場合は、`cdk.json` を開き、`context` 内の `notifiers` 内の `summarizerName` を `AwsSolutionsArchitectJapanese` から `AwsSolutionsArchitectEnglish` などに書き換えてください。その他の設定オプションについては[デプロイガイド](DEPLOY_ja.md)を参照してください。
56 |
57 | ### デプロイの実行
58 | **初期化**
59 |
60 | このリージョンで CDK を使用したことがない場合は、次のコマンドを実行します。
61 |
62 | ```
63 | cdk bootstrap
64 | ```
65 |
66 | **エラーがないことを確認**
67 | ```
68 | cdk synth
69 | ```
70 |
71 | **デプロイの実行**
72 |
73 | ```
74 | cdk deploy
75 | ```
76 |
77 | ## スタックの削除
78 | 不要になった場合は以下のコマンドを実行しスタックを削除します。
79 | ```
80 | cdk destroy
81 | ```
82 | デフォルトでは Amazon DynamoDB テーブルなど一部のリソースが削除されず残る設定となっています。
83 | 完全な削除が必要な場合は、残存したリソースにアクセスし、手動で削除を行ってください。
84 |
85 | ## Third Party Services
86 | このコードは 3rd Party Application である Slack または Microsoft Teams と連携します。利用規約 [Terms Page (Slack)](https://slack.com/main-services-agreement) / [Terms Page (Microsoft 365)](https://www.microsoft.com/en/servicesagreement) や価格設定 [Pricing Page (Slack)](https://slack.com/pricing) / [Pricing Page (Microsoft 365)](https://www.microsoft.com/en-us/microsoft-365/business/compare-all-microsoft-365-business-products?&activetab=tab:primaryr2) はこちらに公開されています。始める前に、価格設定を確認し、使用目的が利用規約に準拠していることを確認することを推奨します。
--------------------------------------------------------------------------------
/bin/cdk_test.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | import 'source-map-support/register';
3 | import * as cdk from 'aws-cdk-lib';
4 | import { WhatsNewSummaryNotifierStack } from '../lib/whats-new-summary-notifier-stack';
5 | import { AwsSolutionsChecks } from 'cdk-nag';
6 | import { Aspects } from 'aws-cdk-lib';
7 |
8 | const app = new cdk.App();
9 | // Add the cdk-nag AwsSolutions Pack with extra verbose logging enabled.
10 | Aspects.of(app).add(new AwsSolutionsChecks({ verbose: true }));
11 | new WhatsNewSummaryNotifierStack(app, 'WhatsNewSummaryNotifierStack', {});
12 |
--------------------------------------------------------------------------------
/bin/whats-new-summary-notifier.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | import 'source-map-support/register';
3 | import * as cdk from 'aws-cdk-lib';
4 | import { WhatsNewSummaryNotifierStack } from '../lib/whats-new-summary-notifier-stack';
5 |
6 | const app = new cdk.App();
7 | new WhatsNewSummaryNotifierStack(app, 'WhatsNewSummaryNotifierStack', {
8 | env: {
9 | account: process.env.CDK_DEFAULT_ACCOUNT,
10 | region: process.env.CDK_DEFAULT_REGION,
11 | },
12 | /* If you don't specify 'env', this stack will be environment-agnostic.
13 | * Account/Region-dependent features and context lookups will not work,
14 | * but a single synthesized template can be deployed anywhere. */
15 | /* Uncomment the next line to specialize this stack for the AWS Account
16 | * and Region that are implied by the current CLI configuration. */
17 | // env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
18 | /* Uncomment the next line if you know exactly what Account and Region you
19 | * want to deploy the stack to. */
20 | // env: { account: '123456789012', region: 'us-east-1' },
21 | /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
22 | });
23 |
--------------------------------------------------------------------------------
/cdk.context.json:
--------------------------------------------------------------------------------
1 | {
2 | "acknowledged-issue-numbers": [
3 | 21902
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/cdk.json:
--------------------------------------------------------------------------------
1 | {
2 | "app": "npx ts-node --prefer-ts-exts bin/whats-new-summary-notifier.ts",
3 | "watch": {
4 | "include": [
5 | "**"
6 | ],
7 | "exclude": [
8 | "README.md",
9 | "cdk*.json",
10 | "**/*.d.ts",
11 | "**/*.js",
12 | "tsconfig.json",
13 | "package*.json",
14 | "yarn.lock",
15 | "node_modules",
16 | "test"
17 | ]
18 | },
19 | "context": {
20 | "modelRegion": "us-east-1",
21 | "modelId": "anthropic.claude-3-sonnet-20240229-v1:0",
22 | "summarizers": {
23 | "AwsSolutionsArchitectEnglish": {
24 | "outputLanguage": "English.",
25 | "persona": "solutions architect in AWS"
26 | },
27 | "AwsSolutionsArchitectJapanese": {
28 | "outputLanguage": "Japanese. Each sentence must be output in polite and formal desu/masu style",
29 | "persona": "solutions architect in AWS"
30 | }
31 | },
32 | "notifiers": {
33 | "AwsWhatsNew": {
34 | "destination": "slack",
35 | "summarizerName": "AwsSolutionsArchitectJapanese",
36 | "webhookUrlParameterName": "/WhatsNew/URL",
37 | "rssUrl": {
38 | "What’s new": "https://aws.amazon.com/about-aws/whats-new/recent/feed/"
39 | }
40 | }
41 | },
42 | "@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
43 | "@aws-cdk/core:stackRelativeExports": true,
44 | "@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
45 | "@aws-cdk/aws-lambda:recognizeVersionProps": true,
46 | "@aws-cdk/aws-lambda:recognizeLayerVersion": true,
47 | "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
48 | "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
49 | "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
50 | "@aws-cdk/core:checkSecretUsage": true,
51 | "@aws-cdk/aws-iam:minimizePolicies": true,
52 | "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
53 | "@aws-cdk/core:validateSnapshotRemovalPolicy": true,
54 | "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
55 | "@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
56 | "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
57 | "@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
58 | "@aws-cdk/core:enablePartitionLiterals": true,
59 | "@aws-cdk/core:target-partitions": [
60 | "aws",
61 | "aws-cn"
62 | ]
63 | }
64 | }
--------------------------------------------------------------------------------
/doc/architecture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/whats-new-summary-notifier/0efb8982d062ae3f8808551409e740ded5b94d81/doc/architecture.png
--------------------------------------------------------------------------------
/doc/example_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/whats-new-summary-notifier/0efb8982d062ae3f8808551409e740ded5b94d81/doc/example_en.png
--------------------------------------------------------------------------------
/doc/example_ja.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/whats-new-summary-notifier/0efb8982d062ae3f8808551409e740ded5b94d81/doc/example_ja.png
--------------------------------------------------------------------------------
/eslint.config.mjs:
--------------------------------------------------------------------------------
1 | import globals from 'globals';
2 | import pluginJs from '@eslint/js';
3 | import tseslint from 'typescript-eslint';
4 | import prettierConfig from 'eslint-config-prettier';
5 |
6 | export default [
7 | { languageOptions: { globals: globals.browser } },
8 | pluginJs.configs.recommended,
9 | ...tseslint.configs.recommended,
10 | prettierConfig,
11 | ];
12 |
--------------------------------------------------------------------------------
/lambda/notify-to-app/index.py:
--------------------------------------------------------------------------------
1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 | # SPDX-License-Identifier: MIT-0
3 |
4 | import boto3
5 | import json
6 | import os
7 | import time
8 | import traceback
9 |
10 | import urllib.request
11 |
12 | from typing import Optional
13 | from botocore.config import Config
14 | from bs4 import BeautifulSoup
15 | from botocore.exceptions import ClientError
16 | import re
17 |
18 | MODEL_ID = os.environ["MODEL_ID"]
19 | MODEL_REGION = os.environ["MODEL_REGION"]
20 | NOTIFIERS = json.loads(os.environ["NOTIFIERS"])
21 | SUMMARIZERS = json.loads(os.environ["SUMMARIZERS"])
22 |
23 | ssm = boto3.client("ssm")
24 |
25 |
26 | def get_blog_content(url):
27 | """Retrieve the content of a blog post
28 |
29 | Args:
30 | url (str): The URL of the blog post
31 |
32 | Returns:
33 | str: The content of the blog post, or None if it cannot be retrieved.
34 | """
35 |
36 | try:
37 | if url.lower().startswith(("http://", "https://")):
38 | # Use the `with` statement to ensure the response is properly closed
39 | with urllib.request.urlopen(url) as response:
40 | html = response.read()
41 | if response.getcode() == 200:
42 | soup = BeautifulSoup(html, "html.parser")
43 | main = soup.find("main")
44 |
45 | if main:
46 | return main.text
47 | else:
48 | return None
49 |
50 | else:
51 | print(f"Error accessing {url}, status code {response.getcode()}")
52 | return None
53 |
54 | except urllib.error.URLError as e:
55 | print(f"Error accessing {url}: {e.reason}")
56 | return None
57 |
58 |
59 | def get_bedrock_client(
60 | assumed_role: Optional[str] = None,
61 | region: Optional[str] = None,
62 | runtime: Optional[bool] = True,
63 | ):
64 | """Create a boto3 client for Amazon Bedrock, with optional configuration overrides
65 |
66 | Args:
67 | assumed_role (Optional[str]): Optional ARN of an AWS IAM role to assume for calling the Bedrock service. If not
68 | specified, the current active credentials will be used.
69 | region (Optional[str]): Optional name of the AWS Region in which the service should be called (e.g. "us-east-1").
70 | If not specified, AWS_REGION or AWS_DEFAULT_REGION environment variable will be used.
71 | runtime (Optional[bool]): Optional choice of getting different client to perform operations with the Amazon Bedrock service.
72 | """
73 |
74 | if region is None:
75 | target_region = os.environ.get(
76 | "AWS_REGION", os.environ.get("AWS_DEFAULT_REGION")
77 | )
78 | else:
79 | target_region = region
80 |
81 | print(f"Create new client\n Using region: {target_region}")
82 | session_kwargs = {"region_name": target_region}
83 | client_kwargs = {**session_kwargs}
84 |
85 | profile_name = os.environ.get("AWS_PROFILE")
86 | if profile_name:
87 | print(f" Using profile: {profile_name}")
88 | session_kwargs["profile_name"] = profile_name
89 |
90 | retry_config = Config(
91 | region_name=target_region,
92 | retries={
93 | "max_attempts": 10,
94 | "mode": "standard",
95 | },
96 | )
97 | session = boto3.Session(**session_kwargs)
98 |
99 | if assumed_role:
100 | print(f" Using role: {assumed_role}", end="")
101 | sts = session.client("sts")
102 | response = sts.assume_role(
103 | RoleArn=str(assumed_role), RoleSessionName="langchain-llm-1"
104 | )
105 | print(" ... successful!")
106 | client_kwargs["aws_access_key_id"] = response["Credentials"]["AccessKeyId"]
107 | client_kwargs["aws_secret_access_key"] = response["Credentials"][
108 | "SecretAccessKey"
109 | ]
110 | client_kwargs["aws_session_token"] = response["Credentials"]["SessionToken"]
111 |
112 | if runtime:
113 | service_name = "bedrock-runtime"
114 | else:
115 | service_name = "bedrock"
116 |
117 | bedrock_client = session.client(
118 | service_name=service_name, config=retry_config, **client_kwargs
119 | )
120 |
121 | return bedrock_client
122 |
123 |
124 | def summarize_blog(
125 | blog_body,
126 | language,
127 | persona,
128 | ):
129 | """Summarize the content of a blog post
130 | Args:
131 | blog_body (str): The content of the blog post to be summarized
132 | language (str): The language for the summary
133 | persona (str): The persona to use for the summary
134 |
135 | Returns:
136 | str: The summarized text
137 | """
138 |
139 | boto3_bedrock = get_bedrock_client(
140 | assumed_role=os.environ.get("BEDROCK_ASSUME_ROLE", None),
141 | region=MODEL_REGION,
142 | )
143 | beginning_word = "