Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions src/cdk-workshop-pipeline-stage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CfnOutput, Stage } from "aws-cdk-lib";
import { Construct } from "constructs";
import { CdkWorkshopStack } from "./cdk-workshop-stack";

export class CDKPipelineStage extends Stage {
public readonly gateWayUrlOutput: CfnOutput;

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

const application = new CdkWorkshopStack(this, "CDKWorkshopStack");
this.gateWayUrlOutput = application.endpointOutput;
}
}
37 changes: 37 additions & 0 deletions src/cdk-workshop-pipeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Stack } from "aws-cdk-lib";
import { Repository } from "aws-cdk-lib/aws-codecommit";
import { CodeBuildStep, CodePipeline, CodePipelineSource } from "aws-cdk-lib/pipelines";
import { Construct } from "constructs";
import { CDKPipelineStage } from "./cdk-workshop-pipeline-stage";

export class CDKPipelineStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id)

const repo = new Repository(this, "CDKWorkshopRepository", {
repositoryName: "CDKWorkshopRepository"
})

const pipeline = new CodePipeline(this, "CDKWorkshopPipeline", {
pipelineName: "CDKWorkshopPipeline",
synth: new CodeBuildStep("Step1", {
input: CodePipelineSource.codeCommit(repo, "feature-pipeline"),
installCommands: ["npm install -g aws-cdk"],
commands: ["npm ci", "npm run build", "npx cdk synth"]
})
})

const deploy = new CDKPipelineStage(this, "Stage1");
const deployStage = pipeline.addStage(deploy);

deployStage.addPost(
new CodeBuildStep("TestGatewayEndpoint", {
projectName: "TestGatewayEndpoint",
envFromCfnOutputs: {
ENDPOINT_URL: deploy.gateWayUrlOutput
},
commands: ["curl -Ssf $ENDPOINT_URL", "curl -Ssf $ENDPOINT_URL/hello", "curl -Ssf $ENDPOINT_URL/users"]
})
)
}
}
10 changes: 8 additions & 2 deletions src/cdk-workshop-stack.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Stack, StackProps } from "aws-cdk-lib";
import { CfnOutput, Stack, StackProps } from "aws-cdk-lib";
import { LambdaRestApi } from "aws-cdk-lib/aws-apigateway";
import { Construct } from "constructs";
import { HitCounter } from "./constructs/hitcounter.js";
import { Hello } from "./constructs/hello.js";

export class CdkWorkshopStack extends Stack {
public readonly endpointOutput: CfnOutput;

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

Expand All @@ -14,8 +16,12 @@ export class CdkWorkshopStack extends Stack {
downstream: hello.handler,
});

new LambdaRestApi(this, "Endpoint", {
const gateway = new LambdaRestApi(this, "Endpoint", {
handler: hitCounter.handler,
});

this.endpointOutput = new CfnOutput(this, "GatewayUrl", {
value: gateway.url,
});
}
}
4 changes: 2 additions & 2 deletions src/cdk-workshop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import { App } from "aws-cdk-lib";
import { CdkWorkshopStack } from "./cdk-workshop-stack.js";
import { CDKPipelineStack } from "./cdk-workshop-pipeline.js";

const app = new App();
new CdkWorkshopStack(app, "CdkWorkshopStack");
new CDKPipelineStack(app, "CdkWorkshopPipelineStack");