In this post, I illustrate how I tackled the problem of making a specific application in Python that would communicate with AWS services.
You can find the code in this repository: https://github.com/gianlucaballa/s3-file-editor
Task: Create an application that allows users to effortlessly share and modify written information such as materials, quantities, and important notes with one another.
The application needs to meet the following criteria:
- Any user should be able to open the application on a pc with a double-click.
- Upon opening the application, users should have immediate access to a simple text file for viewing, editing, and saving (structure for the text file is not necessary – a blank text file suffices).
- The user can read, modify, and save the text file for other users to use.
This application will be specifically used by building engineers to easily share information such as material to buy, quantity and similar notes regarding construction sites.
No overheads: ease of use is vital here.
Key criteria: accessibility, seamless file handling, collaboration.
----------------------------------------------------------------------------------------------------------------------
My solution:
At first, I thought about using RDS in AWS and creating a simple table with 3 columns for a MySQL database. I steered away from this solution because it would have over complicated the code for the execution of SQL commands, without producing any significant benefit.
Instead, I proceeded with the following steps:
- I created an S3 bucket in AWS using a specific user with specific permissions and credentials.
- I uploaded an empty text file with a specific name to the S3 bucket.
- I wrote a Python application using boto3*.
*(Boto3 is the official AWS SDK for Python. It provides an easy-to-use Python interface to interact with various AWS services such as S3. With Boto3, developers can programmatically manage AWS resources, automate tasks, and build applications that leverage AWS services without needing to manually configure API requests).
This solution showed to be effective and satisfied the established key criteria, as it will be demonstrated below.
----------------------------------------------------------------------------------------------------------------------
Explanation:
By sharing and analysing the Python code that I wrote for the application (see point 3. above), you can better understand the operation of the application that I designed.
The code (formatted with Black):
bucket_name
) with the specified key/name of the file (key
) to the local file (local_filename
) on the file system using the function (usually the local file is where the file with the code is on the pc). s3.download_file(bucket_name, key, local_filename) is a specific function provided by Boto3. This final block ensures that the main() function is executed only when the script is run directly, not when it's imported as a module into another script. This allows the script to be used both as a stand-alone program and as a reusable module.
- Ensure that the IAM user associated with the AWS credentials has the necessary permissions to access the specified S3 bucket and perform read/write operations on the objects.
- Make sure to handle sensitive information such as AWS access keys securely.
- This script is intended for educational purposes and can be modified to suit specific requirements.
----------------------------------------------------------------------------------------------------------------------
To transform the script into a clickable .exe, I can use
pyinstaller --onefile my_script_name.py
After PyInstaller finishes, it will create a "dist" directory in the script's directory, containing the executable file. This executable can be distributed to others.