How to use the @aws-cdk/aws-apigateway.LambdaIntegration function in @aws-cdk/aws-apigateway

To help you get started, we’ve selected a few @aws-cdk/aws-apigateway examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github seagull-js / seagull / examples / helloworld / src / cdk / index.ts View on Github external
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',
          'logs:CreateLogStream',
          'logs:PutLogEvents',
          'lambda:InvokeFunction',
          'lambda:InvokeAsync'
github seagull-js / seagull / packages / deploy / src / lib / cdk / stack.ts View on Github external
private addLambda() {
    const name = `${this.appName}-lambda`
    const conf = {
      code: Code.asset(`${this.folder}/.seagull/deploy`),
      description: 'universal route',
      functionName: `${name}-handler`,
      handler: 'dist/assets/backend/lambda.handler',
      memorySize: 3008,
      role: this.role,
      runtime: Runtime.NodeJS810,
      timeout: 300,
    }

    const lambdaFunction = new LambdaFunction(this, name, conf)
    this.defaultIntegration = new LambdaIntegration(lambdaFunction)
  }
github seagull-js / seagull / packages / deploy-aws / src / seagull_stack.ts View on Github external
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
  }
github seagull-js / seagull / packages / deploy / src / cdk_stack.ts View on Github external
private addLambda() {
    const name = `${this.appName}-lambda`
    const code = lambda.Code.asset(`${this.folder}/.seagull/deploy`)
    const description = 'universal route'
    const functionName = `${name}-handler`
    const handler = 'dist/assets/backend/lambda.handler'
    const runtime = lambda.Runtime.NodeJS810
    const timeout = 300
    const conf = { code, description, functionName, handler, runtime, timeout }

    const lambdaFunction = new lambda.Function(this, name, conf)
    this.defaultIntegration = new api.LambdaIntegration(lambdaFunction)
  }
github aws / aws-cdk / packages / @aws-cdk / aws-lambda-event-sources / lib / api.ts View on Github external
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);
  }
}
github cloudcomponents / cdk-components / packages / cdk-codepipeline-slack / src / slack-approval-action.ts View on Github external
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,
                CustomData: this.props.additionalInformation,
                ExternalEntityLink: this.props.externalEntityLink,