in code/java/pipelines-workshop/src/main/java/com/myorg/CdkWorkshopStack.java [24:57]
public CdkWorkshopStack(final Construct parent, final String id, final StackProps props) {
super(parent, id, props);
// Defines a new lambda resource
final Function hello = Function.Builder.create(this, "HelloHandler")
.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"
.build();
// Defines our hitcounter resource
final HitCounter helloWithCounter = new HitCounter(this, "HelloHitCounter", HitCounterProps.builder()
.downstream(hello)
.build());
// Defines an API Gateway REST API resource backed by our "hello" function
final LambdaRestApi gateway = LambdaRestApi.Builder.create(this, "Endpoint")
.handler(helloWithCounter.getHandler())
.build();
// Defines a viewer for the HitCounts table
final TableViewer tv = TableViewer.Builder.create(this, "ViewerHitCount")
.title("Hello Hits")
.table(helloWithCounter.getTable())
.build();
hcViewerUrl = CfnOutput.Builder.create(this, "TableViewerUrl")
.value(tv.getEndpoint())
.build();
hcEndpoint = CfnOutput.Builder.create(this, "GatewayUrl")
.value(gateway.getUrl())
.build();
}