Ocean File Generator Lambda

Overview

This lambda receives file from AWS Kevin account pending bucket, combines the data in that file with data from Dynamodb’s ENV.xxwmm.storepick.ocean_colleague_discount table.

It also copies file to archive folder and deletes file from pending folder of Kevin’s account.

The combined CSV file is then uploaded to Ocado’s GCP bucket from where it will be integrated into OCEAN.

This lambda upload separate file for colleague discount and friends and family discount into Ocado’s GCP bucket

Sequence Diagram

../_images/ocean_upload_cust_file_to_gcp.png

Dependencies

SSM Attribute

See SSM Key

See Ocean SSM Key

Configuration(from config service)

See Configuration(from config service)

AWS Lambda

lambdas.storepick_upload_custs_info_to_ocean.get_application_dependencies()[source]

Returns application_dependencies for a given config_file and ssm_param_store_name

Args:

Returns

object containing config and ssm values

Return type

application_dependencies (class)

Raises

MoriException – if there is any issues with config and ssm name

lambdas.storepick_upload_custs_info_to_ocean.get_s3_client()[source]

Returns s3 client

Args:

Returns

s3 client

Return type

s3_client (class)

lambdas.storepick_upload_custs_info_to_ocean.get_todays_s3_source_filename(application_configuration)[source]

Returns file name to be read from Kevin’s account

Parameters

application_configuration (dict) – contains config values

Returns

file name

Return type

s3_file_name (str)

Raises

Exception – if there is any issue with file read

lambdas.storepick_upload_custs_info_to_ocean.get_file_from_s3(s3_bucket, source_file)[source]

Returns file data read from a file in s3 bucket and it’s pending folder

Parameters
  • s3_bucket (str) – Name of s3 bucket

  • source_file (str) – Name of s3 source file

Returns

streaming object

Return type

s3_client (stream)

Raises

Exception – if there is any issue with file read

lambdas.storepick_upload_custs_info_to_ocean.put_file_into_s3(s3_bucket, target_file, serialized_data)[source]

Returns response after uploading file to s3 bucket

Parameters
  • s3_bucket (str) – Name of s3 bucket

  • target_file (str) – Name of s3 target file

  • serialized_data (byte) – utf-8 encoded bytes

Returns

response from s3 put file operation

Return type

put_response (dict)

Raises

Exception – if there is any issue with file put

lambdas.storepick_upload_custs_info_to_ocean.delete_file_from_s3(s3_bucket, source_file)[source]

Returns response after deleteing file from s3 bucket

Parameters
  • s3_bucket (str) – Name of s3 bucket

  • source_file (str) – Name of s3 target file

Returns

response from s3 delete file operation

Return type

delete_response (dict)

Raises

Exception – if there is any issue with file put

lambdas.storepick_upload_custs_info_to_ocean.get_colleague_data_from_s3(application_configuration, todays_source_file_name)[source]

Returns file contents reaD from s3 bucket

Parameters

application_configuration (dict) – contains config values

Returns

file contents from s3 file

Return type

customer_info_buffer (str)

Raises

Exception – if there is any issue with file read

lambdas.storepick_upload_custs_info_to_ocean.get_ocean_colleague_data(table_key)[source]

Returns all records from colleaaue_discount table

Args:

Returns

customer rercords from dynamodb table

Return type

customer_record_list (list)

lambdas.storepick_upload_custs_info_to_ocean.get_storage_client(application_dependencies)[source]

Returns Google Cloud Storage client object

Parameters

application_dependencies (-) –

Raises

Exception – MoriException containing details about exception

lambdas.storepick_upload_custs_info_to_ocean.upload_file_to_storage(application_dependencies, gcp_storage_file_name, file_content)[source]

Uploads ocean colleague discount data to Google cloud storage

Parameters

application_dependencies (-) –

Returns

showing file upload operation status

Return type

upload_file_flag (Bool)

lambdas.storepick_upload_custs_info_to_ocean.process_ocean_friend_and_family(application_dependencies)[source]

This method will used for processing ocean_friend_and_family customer to upload file into ocean GCP bucket

lambdas.storepick_upload_custs_info_to_ocean.lambda_handler(event, context)[source]

Lambda is called on a daily schedule and queries ocean_colleague_discount table and fetches all records, then prepares customer_info data payload and uploads the same to Google Cloud Storage

Parameters

event (-) –

Example

event = {}
Output:
  • resp (dict):

Example

resp = {
        'statusCode': 200,
        'headers': {'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*'},
        'body': '{
            "status": "success",
            "message": "Ocean file uploaded to Ocado successfully",
            "body": []
        }'
    }