Exemple #1
0
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Defines an AWS Lambda resource
        my_lambda = _lambda.Function(
            self,
            'HelloHandler',
            runtime=_lambda.Runtime.PYTHON_3_7,
            code=_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )

        hello_with_counter = HitCounter(self,
                                        'HelloHitCounter',
                                        downstream=my_lambda)

        gateway = apigw.LambdaRestApi(self,
                                      'Endpoint',
                                      handler=hello_with_counter._handler)

        tv = TableViewer(self,
                         'ViewHitCounter',
                         title='Hello Hits',
                         table=hello_with_counter.table)

        self._hc_endpoint = core.CfnOutput(self,
                                           'GatewayUrl',
                                           value=gateway.url)

        self._hc_viewer_url = core.CfnOutput(self,
                                             'TableViewerUrl',
                                             value=tv.endpoint)
Exemple #2
0
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Defines an AWS Lambda resource
        my_lambda = _lambda.Function(
            self,
            'HelloHandler',
            function_name='dyna-hello',
            runtime=_lambda.Runtime.PYTHON_3_7,
            code=_lambda.Code.asset('lambda'),
            handler='hello.handler',
        )

        # Add a hit counter to stack
        hello_with_counter = HitCounter(
            self,
            'HelloHitCounter',
            downstream=my_lambda,
        )

        apigw.LambdaRestApi(
            self,
            'Endpoint',

            # change the API Gateway handler to hello_with_counter.handler
            # instead of my_lambda
            handler=hello_with_counter.handler,
        )
    def __init__(self, scope: core.Construct, construct_id: str,
                 **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        my_lambda = _lambda.Function(self,
                                     'HelloHandler',
                                     runtime=_lambda.Runtime.PYTHON_3_7,
                                     code=_lambda.Code.asset('lambda'),
                                     handler='hello.handler')

        hello_with_counter = HitCounter(self,
                                        'HelloWithCounter',
                                        downstream=my_lambda)

        apigw.LambdaRestApi(
            self,
            'Endpoint',
            handler=hello_with_counter.handler,
        )

        TableViewer(self,
                    'ViewHitCounter',
                    title='Hello Hits',
                    table=hello_with_counter.table,
                    sort_by='-hits')
    def __init__(self, scope: core.Construct, construct_id: str,
                 **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Define an AWS Lambda resource
        my_lambda = _lambda.Function(self,
                                     'HelloHandler',
                                     runtime=_lambda.Runtime.PYTHON_3_8,
                                     code=_lambda.Code.asset('lambda'),
                                     handler='hello.handler')

        hello_with_counter = HitCounter(self,
                                        'HelloHitCounter',
                                        downstream=my_lambda)

        # API Gateway
        apigw.LambdaRestApi(self,
                            'Endpoint',
                            handler=hello_with_counter.handler)

        # Table Viewer
        TableViewer(self,
                    'ViewHitCounter',
                    title='Hello Hits',
                    table=hello_with_counter.table,
                    sort_by="-hits")
Exemple #5
0
    def __init__(self, scope: core.Construct, construct_id: str,
                 **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        my_lambda = _lambda.Function(
            self,
            "HelloHandler",
            runtime=_lambda.Runtime.PYTHON_3_7,
            code=_lambda.Code.from_asset(os.path.join(os.getcwd(), "lambda")),
            handler="hello.handler",
        )

        hello_with_counter = HitCounter(
            self,
            "HelloHitCounter",
            downstream=my_lambda,
        )

        apigw.LambdaRestApi(
            self,
            "Endpoint",
            handler=hello_with_counter.handler,
        )

        TableViewer(
            self,
            "ViewHitCounter",
            title="Hello Hits",
            table=hello_with_counter.table,
        )
    def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # define lambda reosurces
        my_lambda = _lambda.Function(
                self, "HelloHandler",
                runtime=_lambda.Runtime.PYTHON_3_7, 
                code=_lambda.Code.asset('lambda'),
                handler='hello.handler'
         )

        # hitcounter lamnda function
        hello_with_counter = HitCounter(
            self,
            'HelloHitCounter',
            downstream=my_lambda,
        )
        
        # whenever our endpoint is hit, API Gateway will route the request to our hit counter handler,
        # which will log the hit and relay it over to the my_lambda function.
        apigw.LambdaRestApi(
             self, 
             'Endpoint',
             handler=hello_with_counter.handler,
         )

        # to view the dynamodb table         
        TableViewer(
            self,
            'Hello Hits',
            table=hello_with_counter._table
        )

        # demostrating Token
        print(my_lambda.function_name)
Exemple #7
0
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Defines an AWS Lambda resource
        my_lambda = _lambda.Function(
            self,
            'HelloHandler',
            runtime=_lambda.Runtime.PYTHON_3_7,
            code=_lambda.Code.asset('lambda'),
            handler='hello.handler',
        )

        hello_with_counter = HitCounter(
            self,
            'HelloHitCounter',
            downstream=my_lambda,
        )

        apigw.LambdaRestApi(
            self,
            'Endpoint',
            handler=hello_with_counter.handler,
        )

        TableViewer(self,
                    'ViewHitCounter',
                    title='Hello Hits',
                    table=hello_with_counter.table)
    def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        my_lambda = aws_lambda.Function(
            self,
            'HelloHandler',
            runtime=aws_lambda.Runtime.PYTHON_3_7,
            code=aws_lambda.Code.asset('lambda'),
            handler='hello.handler'  # Name of the file, plus the name of the function
        )

        hello_with_counter = HitCounter(
            self,
            'HelloHitCounter',
            downstream=my_lambda
        )

        aws_apigateway.LambdaRestApi(
            self,
            'Endpoint',
            handler=hello_with_counter.handler
        )
        viewer(
            self,
            'ViewHitCounter',
            title='The hits',
            table=hello_with_counter.table,
            sort_by="hits",
        )
    def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        hello_handler = _lambda.Function(self, 'HelloHandler', runtime=_lambda.Runtime.PYTHON_3_8,
                                         code=_lambda.Code.asset('lambda'), handler='hello.handler')
        hitcount_hello = HitCounter(self, 'HitCounterHello', downstream=hello_handler)
        hello_api = apigw.LambdaRestApi(self, 'HelloHandlerAPI', handler=hitcount_hello.handler)

        table_viewer = TableViewer(self, 'HitCountTableViewer', table=hitcount_hello.table)
    def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        my_lambda = _lambda.Function(
            self, 'HelloHandler',
            runtime = _lambda.Runtime.PYTHON_3_7,
            code = _lambda.Code.asset('lambda'),
            handler = 'hello.handler',
        )

        hello_with_counter = HitCounter (
            self, 'HelloHitCounter',
            downstream=my_lambda,
        )

        apigw.LambdaRestApi(
            self, 'Endpoint',
            handler=hello_with_counter.handler,
        )
    def __init__(self, scope: core.Construct, construct_id: str,
                 **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)
        """ queue = sqs.Queue(
            self, "PythonQueue",
            visibility_timeout=core.Duration.seconds(300),
        )

        topic = sns.Topic(
            self, "PythonTopic"
        )

        topic.add_subscription(subs.SqsSubscription(queue)) """

        my_lambda = _lambda.Function(
            self,
            'HelloHandler',
            runtime=_lambda.Runtime.PYTHON_3_7,
            code=_lambda.Code.asset('lambda'),
            handler='hello.handler',
        )

        hello_with_counter = HitCounter(
            self,
            'HelloHitCounter',
            downstream=my_lambda,
        )

        apigw.LambdaRestApi(
            self,
            'Endpoint',
            handler=hello_with_counter.handler,
        )

        TableViewer(
            self,
            'ViewHitCounter',
            title='Hello Hits',
            table=hello_with_counter.table,
        )
Exemple #12
0
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # The code that defines your stack goes here

        my_lambda = _lambda.Function(
            self, "HelloHandler",
            code=_lambda.Code.from_asset('lambda'),
            runtime=_lambda.Runtime.PYTHON_3_7,
            handler='hello.handler'
        )
       
        hello_with_counter = HitCounter(
           self, "HelloHitCounter",
           downstream= my_lambda
        )

        
        my_apigw = apigw.LambdaRestApi(
            self, "Endpoint",
            handler=hello_with_counter.handler,
        )        
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        my_lambda = _lambda.Function(self,
                                     'HelloHandler',
                                     runtime=_lambda.Runtime.PYTHON_3_7,
                                     code=_lambda.Code.asset('hello/lambda'),
                                     handler='hello.handler')

        counter = HitCounter(self, "hello-hit-counter", my_lambda)

        apigw.LambdaRestApi(
            self,
            'Endpoint',
            handler=counter.handler,
        )

        TableViewer(self,
                    "ViewHitCounts",
                    title="Hello hits",
                    table=counter._table,
                    sort_by="hits")
Exemple #14
0
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # The code that defines your stack goes here
        my_lambda = _lambda.Function(self,
                                     "HelloHandler",
                                     runtime=_lambda.Runtime.PYTHON_3_7,
                                     code=_lambda.Code.asset('lambda'),
                                     handler="hello.handler")

        hello_with_counter = HitCounter(self,
                                        "HelloHitCounter",
                                        downstream=my_lambda)

        apigw.LambdaRestApi(self,
                            "Endpoint",
                            handler=hello_with_counter.handler)

        TableViewer(self,
                    "ViewHitCounter",
                    title="Hello Hits",
                    sort_by="-hits",
                    table=hello_with_counter.table)
    def __init__(self, scope: core.Construct, construct_id: str,
                 **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Lambda resource
        my_lambda = _lambda.Function(self,
                                     'myLambdaHandler',
                                     runtime=_lambda.Runtime.PYTHON_3_8,
                                     code=_lambda.Code.asset('lambda'),
                                     handler='myLambda.handler')

        # hitcounter
        myLambda_with_counter = HitCounter(
            self,
            'HelloHitCounter',
            downstream=my_lambda,
        )

        #API GW resource
        apigw.LambdaRestApi(
            self,
            'Endpoint',
            handler=myLambda_with_counter.handler,
        )