Package: rispack
Rispack - Pack of shared libraries from RisparRispack is a collection of libraries developed by Rispar to help with serverless development on AWS.HandlerThe Handler module is designed to make serverless development on AWS Lambda functions easier. There is two types of handler: route and job.Route HandlerTheroutedecorator is used to define a route (http endpoint) for a Lambda function. It handles the API requests and responses and makes it easy to define the route handlers.Here's an example of using the route decorator to define a route handler:fromrispack.handlerimportRequest,Response,routefromactionsimportGetProfilefromparamsimportGetProfileParams@routedefget_profile(request:Request):params=GetProfileParams.load(request.params)profile=GetProfile.run(params)returnResponse.ok(profile)Theroutedecorator handles the incoming request and passes it to the decorated function. The decorated function must return a Response object with the appropriate HTTP status code and response body.InterceptorsThe route decorator also supports interceptors, which are functions that can be run before the route handler to perform additional checks or processing.The two built-in interceptors are thetoken interceptorand therole interceptor.Token InterceptorThe token interceptor checks if the request has a valid authorization token. You can add the token parameter to the route decorator to enable the token interceptor.@route(token=True)defcreate_loan(request:Request):# ...Role InterceptorThe role interceptor checks if the user has the required role to access the route. You can add the role parameter to the route decorator to enable the role interceptor.@route(role="PROFILE_VIEW")defget_profile(request:Request):# ...Job HandlerThe Rispack handler module also includes functionality for background job processing via the@jobdecorator. The provided job function parameter,
is based on the event being processed, which could be any supported AWS SAM events.There is 2 built-in types, provided by the Rispack:FileRecord - For S3 file events.EventRecord - For SQS events (more details below).Here is an example of a job using an FileRecord parameter:@jobdefprocess_file(record:FileRecord):# do some processing with the fileAnd another one using EventRecord:@jobdefprocess_event(record:EventRecord):# do something with the event payloadEvent SystemRispack's event system is designed around a fanout pattern, where events are published to SNS and then distributed to SQS queues. Each queue is responsible for handling the specific event that it receives.It uses a strict payload format that must be used to ensure proper functionality. This format is defined by the EventRecord class:classEventRecord:id:UUIDaggregate_id:UUIDpayload:Dict[str,Any]type:strorigin:strat:datetimeversion:strTheEventRecordclass contains information such as the event ID, the aggregate ID, the payload data, and the event type, among other fields. This information is used by the event system to ensure that events are handled correctly and consistently.DatabaseManage connection to RDS Cluster (or RDS Proxy) via Secret Manager.AWSThe AWS module included in the Rispack provides functions that simplify the use of some AWS services in Python. Here's a brief explanation of each function:get_signed_auth()Returns a signed URI for calling endpoints with IAM authorization. This is useful for accessing protected APIs, such as those created with AWS API Gateway.get_ssm_parameter(name: str, encrypted: bool = False) -> strReturns a parameter value from the Systems Manager parameter store.name: The name of the parameter.encrypted: Flag indicating whether the value is encrypted or not.put_ssm_parameter(name: str, value: str, param_type: str = "String", overwrite: bool = True) -> intCreates or updates a parameter in the Systems Manager parameter store.name: The name of the parameter.value: The value to be stored.param_type: The type of the parameter. Default is "String".overwrite: Whether to overwrite an existing parameter. Default is True.get_secret(name: str) -> strReturns a secret value from AWS Secrets Manager.name: The name of the secret.enqueue(queue_name: str, message: Any) -> NoneAdds a new message to an Amazon Simple Queue Service (SQS) queue.queue_name: The name of the SQS queue.message: The message to publish.get_url(bucket_name: str, object: str, expiration_in_seconds: int = 300) -> strReturns a presigned URL for an Amazon S3 object.bucket_name: The name of the S3 bucket.object: The complete object path.expiration_in_seconds: The period in seconds until URL expiration. Default is 300 (5 minutes).SchemasBase Schema for entities, events and other data classes.LoggerAWS Lambda Powertools loggerStoresBase Store class and decorators to work with transactions