+++ title = "アプリに table viewer を追加" weight = 300 +++ ## Table viewer をスタックに追加 `TableViewer` をスタックに追加するには、`src/CdkWorkshop/CdkWorkshopStack.cs` に次のコードでハイライトされている部分を追加します。 {{}} using Amazon.CDK; using Amazon.CDK.AWS.APIGateway; using Amazon.CDK.AWS.Lambda; using Cdklabs.DynamoTableViewer; using Construct; namespace CdkWorkshop { public class CdkWorkshopStack : Stack { public CdkWorkshopStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) { // Defines a new lambda resource var hello = new Function(this, "HelloHandler", new FunctionProps { Runtime = Runtime.NODEJS_14_X, // execution environment Code = Code.FromAsset("lambda"), // Code loaded from the "lambda" directory Handler = "hello.handler" // file is "hello", function is "handler" }); // Defines out HitCounter resource var helloWithCounter = new HitCounter(this, "HelloHitCounter", new HitCounterProps { Downstream = hello }); // Defines an API Gateway REST API resource backed by our "hello" function. new LambdaRestApi(this, "Endpoint", new LambdaRestApiProps { Handler = helloWithCounter.Handler }); // Defines a new TableViewer resource new TableViewer(this, "ViewerHitCount", new TableViewerProps { Title = "Hello Hits", Table = //??? }); } } } {{}} ## table の値は? お気づきのように、`TableViewer` では `table` というプロパティを指定する必要があります。 やりたいことは、何らかの方法で HitCounter の裏にある DynamoDB のテーブルにアクセスすることです。しかし、現在の HitCounter の API は、パブリックメンバーとして、テーブルを公開していません。 --- 次のセクションでは、テーブルを `HitCounter` のプロパティとして公開します。そうすればスタックからアクセスできるようになります。