コード例 #1
0
 def apigw_resource_logic_id(self) -> str:
     """
     Api Gateway Resource Logic Id is Full Resource Path in Camelcase format
     with a Prefix.
     """
     return "ApigwResource{}".format(
         camelcase(self.rel_module_name.replace(".", "-")))
コード例 #2
0
    def s3_event_bucket_logic_id(self):
        """
        logic id for ``s3.Bucket`` of the Lambda Event Mapping S3 Bucket.

        :rtype: str
        """
        if self.s3_event_bucket_basename is NOTHING:
            raise TypeError
        if isinstance(self.s3_event_bucket_basename, str):
            return "S3Bucket{}".format(camelcase(
                self.s3_event_bucket_basename))
        else:
            raise TypeError
コード例 #3
0
 def get_authorizer_id(cls, rel_module_name):
     return "ApigwAuthorizer{}".format(
         camelcase(rel_module_name.replace(".", "-")))
コード例 #4
0
    def apigw_method_options_for_cors_aws_object(self) -> apigateway.Method:
        """

        **中文文档**

        为了开启 Cors, 对于 Api Resource 是需要一个 Options Method 专门用于获取
        服务器的设置. 这事因为浏览器在检查到跨站请求时, 会使用 Options 方法获取服务器的
        跨站访问设置, 如果不满则, 浏览爱则会返回错误信息.
        """
        # For cors, options method doesn't need a lambda function
        depends_on = [
            self.apigw_resource_aws_object,
        ]

        # Integration Request
        request_template = {"application/json": "{\"statusCode\": 200}"}

        # Integration Response
        access_control_allow_headers = "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token"

        if self.apigw_method_authorizer is not NOTHING:
            if self.apigw_authorizer_token_type_header_field is not NOTHING:
                access_control_allow_headers = access_control_allow_headers \
                                               + ",{}".format(self.apigw_authorizer_token_type_header_field)

        response_parameters = {
            "method.response.header.Access-Control-Allow-Origin":
            "'*'",
            "method.response.header.Access-Control-Allow-Methods":
            "'OPTIONS,GET,POST'",
            "method.response.header.Access-Control-Allow-Headers":
            "'{}'".format(access_control_allow_headers),
        }
        response_templates = {"application/json": ""}
        integration = apigateway.Integration(
            Type="MOCK",
            RequestTemplates=request_template,
            IntegrationResponses=[
                apigateway.IntegrationResponse(
                    StatusCode="200",
                    ContentHandling="CONVERT_TO_TEXT",
                    ResponseParameters=response_parameters,
                    ResponseTemplates=response_templates,
                )
            ],
            PassthroughBehavior="WHEN_NO_MATCH",
        )
        if self.apigw_method_int_passthrough_behavior is not NOTHING:
            integration.PassthroughBehavior = self.apigw_method_int_passthrough_behavior
        if self.apigw_method_int_timeout_in_milli is not NOTHING:
            integration.TimeoutInMillis = self.apigw_method_int_timeout_in_milli

        # Method Response
        method_responses = [
            apigateway.MethodResponse(
                StatusCode="200",
                ResponseModels={"application/json": "Empty"},
                ResponseParameters={
                    "method.response.header.Access-Control-Allow-Origin":
                    False,
                    "method.response.header.Access-Control-Allow-Methods":
                    False,
                    "method.response.header.Access-Control-Allow-Headers":
                    False,
                })
        ]

        apigw_method = apigateway.Method(
            title="ApigwMethod{}Options".format(
                camelcase(self.rel_module_name.replace(".", "-"))),
            RestApiId=Ref(self.apigw_restapi),
            ResourceId=Ref(self.apigw_resource_aws_object),
            AuthorizationType="NONE",
            HttpMethod="OPTIONS",
            MethodResponses=method_responses,
            Integration=integration,
        )

        apigw_method.DependsOn = depends_on

        return apigw_method
コード例 #5
0
 def apigw_method_logic_id(self) -> str:
     return "ApigwMethod{}".format(
         camelcase(self.rel_module_name.replace(".", "-")) +
         camelcase(self._py_function.__name__))
コード例 #6
0
 def lbd_func_logic_id(self) -> str:
     return "LbdFunc{}".format(
         camelcase(self.rel_module_name.replace(".", "-")) +
         camelcase(self._py_function.__name__))