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")
Exemplo n.º 3
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,
        )
Exemplo n.º 4
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,
        )

        TableViewer(
            self,
            'ViewHitCounter',
            title='Hello Hits',
            table=hello_with_counter.table,
        )
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        twilio_lambda = _lambda.Function(self, "twilio", runtime=_lambda.Runtime.PYTHON_3_6,
                                          handler="lambda_handler.main", timeout=core.Duration.seconds(20),
                                          memory_size=128, code=_lambda.Code.asset("./lambda/twilio"),
                                          description='Hool de integración con twilio')

        twilio_lambda.add_to_role_policy(iam.PolicyStatement(actions=["lex:PostText", "lex:PostContent"],
                                               resources=["*"]))
        # TODO : agregar permiso para lex:PostText lex:PostContent

        # The code that defines your stack goes here
        fullfillment_lambda = _lambda.Function(
            self,
            "FULLFILMENT",
            runtime=_lambda.Runtime.PYTHON_3_6,
            handler="lambda_handler.main",
            timeout=core.Duration.seconds(20),
            memory_size=256,
            code=_lambda.Code.asset("./lambda/fulfillment"),
            description="Procesa la completación del Intent",
        )

        fullfillment_lambda.add_permission('default',
        principal=iam.ServicePrincipal('lex.amazonaws.com'),action="lambda:invokeFunction",
        source_arn="arn:aws:lex:{}:{}:intent:*".format(self.region, self.account) )

        
        appointments_table = ddb.Table(
            self, "AGENDAMIENTOS",
            partition_key=ddb.Attribute(name="user_phone", type=ddb.AttributeType.STRING),
            sort_key=ddb.Attribute(name="request_time", type=ddb.AttributeType.STRING))

        appointments_table.grant_full_access(fullfillment_lambda)
        fullfillment_lambda.add_environment("APPOINTMENTS_TABLE", appointments_table.table_name)

        TableViewer(
            self, 'ViewHitCounter',
            title='Citas Realizadas vía Whatsapp',
            table=appointments_table
        ) 
        

        api = api_cors_lambda(self, "API", twilio_lambda)

        _lexbot = lexbot(self,"appointments-bot",f_lambda=fullfillment_lambda, bot_locale=BOT_LANGUAGE)
Exemplo n.º 10
0
    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,
        )
    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")
Exemplo n.º 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",
                                     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)