Giter Club home page Giter Club logo

cdk-eventbridge-socket's Issues

Add a authorizer function for the API Gateway (Websocket) endpoint

By default the websocket is open for anyone to connect too.

Think it would be better practice if there was a basic lambda that maybe could verify a token of some sort? Like the example seen here https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html

exports.handler = async(event) => {
    let response = {
        "isAuthorized": false,
        "context": {
            "stringKey": "value",
            "numberKey": 1,
            "booleanKey": true,
            "arrayKey": ["value1", "value2"],
            "mapKey": {"value1": "value2"}
        }
    };
    
    if (event.headers.authorization === "secretToken") {
        response = {
            "isAuthorized": true,
            "context": {
                "stringKey": "value",
                "numberKey": 1,
                "booleanKey": true,
                "arrayKey": ["value1", "value2"],
                "mapKey": {"value1": "value2"}
            }
        };
    }

    return response;

};

Maybe the websocket could send a authorization header, then we could allow the connection if it matches....

Error: Type 'App' is missing the following properties

Hi,

I have tried using this with latest CDK (version 2.29.0 (build 47d7ec4)) and Node 18.4 and I am always getting this error one way or the other:

/root/cdk-debug-evbridge/node_modules/ts-node/src/index.ts:843                                                              
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);                                                       
           ^                                                                                                                
TSError: ⨯ Unable to compile TypeScript:                                                                                    
bin/cdk-debug-evbridge.ts:7:27 - error TS2345: Argument of type 'import("/root/cdk-debug-evbridge/node_modules/aws-cdk-lib/c
ore/lib/app").App' is not assignable to parameter of type 'import("/root/cdk-debug-evbridge/node_modules/@aws-cdk/core/lib/a
pp").App'.                                                                                                                  
  Type 'App' is missing the following properties from type 'App': onValidate, onPrepare, onSynthesize, validate, and 2 more.
                                                                                                                            
7 new CdkDebugEvbridgeStack(app, 'CdkDebugEvbridgeStack', {                                                                 
                            ~~~                                                                                             
                                                                                                                            
    at createTSError (/root/cdk-debug-evbridge/node_modules/ts-node/src/index.ts:843:12)                                    
    at reportTSError (/root/cdk-debug-evbridge/node_modules/ts-node/src/index.ts:847:19)
    at getOutput (/root/cdk-debug-evbridge/node_modules/ts-node/src/index.ts:1057:36)                                       
    at Object.compile (/root/cdk-debug-evbridge/node_modules/ts-node/src/index.ts:1411:41)
    at Module.m._compile (/root/cdk-debug-evbridge/node_modules/ts-node/src/index.ts:1596:30)                               
    at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
    at Object.require.extensions.<computed> [as .ts] (/root/cdk-debug-evbridge/node_modules/ts-node/src/index.ts:1600:12)
    at Module.load (node:internal/modules/cjs/loader:988:32)                                                                
    at Function.Module._load (node:internal/modules/cjs/loader:834:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  diagnosticCodes: [ 2345 ]
}

Subprocess exited with error 1

Here's my code:

import * as cdk from '@aws-cdk/core';
import { EventBridgeWebSocket } from 'cdk-eventbridge-socket';

export class CdkDebugEvbridgeStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new EventBridgeWebSocket(this, 'CdkDebugEvbridgeSockets', {
      bus: 'default',

      // This example shows how to listen for all events
      eventPattern: {
        account: ['1234567891234'],
      },
      stage: 'dev',
    });
    // The code that defines your stack goes here

    // example resource
    // const queue = new sqs.Queue(this, 'CdkDebugEvbridgeQueue', {
    //   visibilityTimeout: cdk.Duration.seconds(300)
    // });
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.