Created
October 4, 2021 20:28
-
-
Save farminf/eba6cd21c65d78dea70152b8c304cfd6 to your computer and use it in GitHub Desktop.
CDK stack for API Gateway and Lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as cdk from '@aws-cdk/core'; | |
import * as lambda from '@aws-cdk/aws-lambda'; | |
import * as apigateway from "@aws-cdk/aws-apigateway"; | |
export class PRAlertStack extends cdk.Stack { | |
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
// our function | |
const handler = new lambda.Function(this, "alertHandler", { | |
runtime: lambda.Runtime.NODEJS_12_X, | |
code: lambda.Code.fromAsset("resources"), | |
handler: "alert.main", | |
environment: { | |
SLACK_CHANNEL_URL: "{GET_THIS_FROM_YOUR_SLACK_APP}", | |
WEBHOOK_SECRET:"{GET_THIS_FROM_YOUR_GITHUB_REPO_WEBHOOKS_SETTING}" | |
} | |
}); | |
// our API | |
const api = new apigateway.RestApi(this, "pr-alert-api", { | |
restApiName: "PR Alert Service", | |
}); | |
const postPRAlert = new apigateway.LambdaIntegration(handler, { | |
requestTemplates: { "application/json": '{ "statusCode": "200" }' } | |
}); | |
api.root.addMethod("POST", postPRAlert); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment