+++ title = "HitCounter API の定義" weight = 100 +++ ## Create a new file for our hit counter construct `src/main/java/com/myorg` の配下に `HitCounterProps.java` というファイルを以下の内容で作成します。 ```java package com.myorg; import software.amazon.awscdk.services.lambda.IFunction; public interface HitCounterProps { // Public constructor for the props builder public static Builder builder() { return new Builder(); } // The function for which we want to count url hits IFunction getDownstream(); // The builder for the props interface public static class Builder { private IFunction downstream; public Builder downstream(final IFunction function) { this.downstream = function; return this; } public HitCounterProps build() { if(this.downstream == null) { throw new NullPointerException("The downstream property is required!"); } return new HitCounterProps() { @Override public IFunction getDownstream() { return downstream; } }; } } } ``` また、 `HitCounter.java` というファイルを以下の内容で作成します。 ``` java package com.myorg; import software.constructs.Construct; public class HitCounter extends Construct { public HitCounter(final Construct scope, final String id, final HitCounterProps props) { super(scope, id); // TODO } } ``` これらのファイルを保存します。 ## ここで何が起こったのでしょうか? * `HitCounter` という名前のコンストラクトクラスを新しく定義しています。 * これまでどおり、`scope`、`id`、`props` のコンストラクター引数を設定し、基底クラスである cdk.Construct に伝搬させます。 * `props` の引数の型は `HitCounterProps`で、これには `IFunction` 型の `getDownStream` とpropsを作成する `Builder` が含まれます。 前の章で作成したLambda関数をここに接続して、HitCountが機能するようにします。 ---- 次に、HitCounter ハンドラーのコードを記述します。