Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(parent: cdk.App, id: string, props?: cdk.StackProps) {
super(parent, id, props)
const lambdaName = `${pkg.name}-handler`
const lambdaParams: lambda.FunctionProps = {
code: lambda.Code.asset('.'),
description: 'universal route',
functionName: lambdaName,
handler: 'dist/assets/backend/lambda.handler',
runtime: lambda.Runtime.NodeJS810,
}
const fn = new lambda.Function(this, lambdaName, lambdaParams)
const apiGateway = new api.RestApi(this, `${pkg.name}-api-gateway`, {
binaryMediaTypes: ['*/*'],
})
const defaultIntegration = new api.LambdaIntegration(fn)
apiGateway.root.addMethod('GET', defaultIntegration)
const proxy = apiGateway.root.addResource('{any+}')
proxy.addMethod('GET', defaultIntegration)
const role = new iam.Role(this, `${pkg.name}-Role`, {
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
})
// TODO: PLEASE! PLEASE! WORK THIS OVER!!! this could be a viable security breach.
role.addToPolicy(
new iam.PolicyStatement()
.addAllResources()
.addActions(
'sts:AssumeRole',
public constructor(parent: App, name: string, props?: StackProps) {
super(parent, name, props);
const api = new RestApi(this, 'github-webhook');
api.root.addMethod('POST');
const githubApiToken = process.env.API_TOKEN as string;
// @example https://github.com/cloudcomponents/cdk-components
const githubRepoUrl = process.env.REPO_URL as string;
// @see https://developer.github.com/v3/activity/events/types/
const events = ['*'];
new GithubWebhook(this, 'GithubWebhook', {
githubApiToken,
githubRepoUrl,
payloadUrl: api.url,
events,
logLevel: 'debug',
public bind(target: lambda.IFunction): void {
const id = `${target.node.uniqueId}:ApiEventSourceA7A86A4F`;
const stack = Stack.of(target);
let api = stack.node.tryFindChild(id) as apigw.RestApi;
if (!api) {
api = new apigw.RestApi(stack, id, {
defaultIntegration: new apigw.LambdaIntegration(target),
});
}
const resource = api.root.resourceForPath(this.path);
resource.addMethod(this.method, undefined, this.options);
}
}
addUniversalApiGateway(apiGWName: string, lambda: Lambda, stageName: string) {
const name = `${this.id}-${apiGWName}`
const defaultIntegration = new LambdaIntegration(lambda)
const conf = { binaryMediaTypes: ['*/*'], deployOptions: { stageName } }
const apiGateway = new RestApi(this, name, conf)
const proxy = apiGateway.root.addResource('{any+}')
apiGateway.root.addMethod('GET', defaultIntegration)
apiGateway.root.addMethod('POST', defaultIntegration)
apiGateway.root.addMethod('DELETE', defaultIntegration)
proxy.addMethod('GET', defaultIntegration)
proxy.addMethod('POST', defaultIntegration)
proxy.addMethod('DELETE', defaultIntegration)
return apiGateway
}
private addApiGateway() {
const name = `${this.appName}-api-gateway`
const conf = { binaryMediaTypes: ['*/*'] }
this.apiGateway = new RestApi(this, name, conf)
const apiKeyConfig = {
description: 'api key for general api route',
enabled: true,
generateDistinctId: true,
name: `${name}-api-key`,
stageKeys: [
{ restApiId: new Token(this.apiGateway.restApiId), stageName: 'prod' },
],
}
const usagePlanConfig = {
apiStages: [
{ apiId: new Token(this.apiGateway.restApiId), stage: 'prod' },
],
description: 'universal plan to secure the api gateway',
usagePlanName: 'universal plan',
private addApiGateway() {
const name = `${this.appName}-api-gateway`
const conf = { binaryMediaTypes: ['*/*'] }
this.apiGateway = new api.RestApi(this, name, conf)
const proxy = this.apiGateway.root.addResource('{any+}')
this.apiGateway.root.addMethod('GET', this.defaultIntegration)
proxy.addMethod('GET', this.defaultIntegration)
this.apiGatewayDomain = getApiGatewayDomain(this.apiGateway.url)
this.apiGatewayOriginPath = getApiGatewayPath(this.apiGateway.url)
}
public constructor(scope: App, id: string, props?: StackProps) {
super(scope, id, props);
const api = new RestApi(this, 'Endpoint');
api.root.addMethod('POST');
const accessToken = process.env.ACCESS_TOKEN as string;
const spaceId = process.env.SPACE_ID as string;
const topics = ['Entry.create'];
new ContentfulWebhook(this, 'ContentfulWebhook', {
accessToken,
spaceId,
name: 'ExampleWebhook',
url: api.url,
topics,
logLevel: 'debug',
});
topic.addSubscription(new LambdaSubscription(approvalRequester));
const approvalHandler = new Function(
scope,
'SlackApprovalHandlerFunction',
{
runtime: Runtime.NODEJS_10_X,
handler: 'lib/approval-handler.handler',
code: Code.fromAsset(
path.join(__dirname, '..', 'lambda', 'bundle.zip'),
),
environment,
},
);
const api = new RestApi(scope, 'SlackApprovalApi');
api.root.addProxy({
defaultIntegration: new LambdaIntegration(approvalHandler),
});
approvalHandler.addToRolePolicy(
new PolicyStatement({
actions: ['codepipeline:PutApprovalResult'],
resources: [
`${stage.pipeline.pipelineArn}/${stage.stageName}/${this.props.actionName}`,
],
}),
);
return {
configuration: {
NotificationArn: topic.topicArn,