How to write a Dictionary to JSON file in S3 Bucket using boto3 and Python

If you want to write a python dictionary to a JSON file in S3 then you can use the code examples below.

There are two code examples doing the same thing below because boto3 provides a client method and a resource method to edit and access AWS S3.

Related: Reading a JSON file in S3 and store it in a Dictionary using boto3 and Python

Writing Python Dictionary to an S3 Object using boto3 Client

import boto3
import json
from datetime import date

data_dict = {
    'Name': 'Daikon Retek',
    'Birthdate': date(2000, 4, 7),
    'Subjects': ['Math', 'Science', 'History']
}

# Convert Dictionary to JSON String
data_string = json.dumps(data_dict, indent=2, default=str)


# Upload JSON String to an S3 Object
client = boto3.client('s3')

client.put_object(
    Bucket='radishlogic-bucket', 
    Key='s3_folder/client_data.json',
    Body=data_string
)
Continue reading How to write a Dictionary to JSON file in S3 Bucket using boto3 and Python

How to download files from S3 Bucket using boto3 and Python

If you want to download a file from an AWS S3 Bucket using Python, then you can use the sample codes below.

The codes below use AWS SDK for Python named boto3.

boto3 provides three methods to download a file.

  1. download_file()
  2. download_fileobj() – with multipart upload
  3. get_object()

Then for each method, you can use the client class or the resource class of boto3.

Both of the classes will be used for each of the methods above.

Note: All examples will work with any Python3 environment running in Windows, MacOS or Linux operating systems.

Continue reading How to download files from S3 Bucket using boto3 and Python

How to upload a file to S3 Bucket using boto3 and Python

There are 3 ways to upload or copy a file from your local computer to an Amazon Web Services (AWS) S3 Bucket using boto3. All of these will be discussed in this post including multipart uploads.

The codes below will work if you are Windows, Mac, and Linux. Will also work if you working in a Lambda function using Python.

Each method will have an example using boto3 S3 client and S3 resource so you can use whatever method you are comfortable with.


Continue reading How to upload a file to S3 Bucket using boto3 and Python

Convert boto3 AMI Creation Date from string to Python datetime

When retrieving the AMI Creation Date from boto3 it returns a string data type. Visually, this is okay but it is challenging to do operations and comparisons to the AMI Creation Date in this format.

To solve the issue we need to convert the AMI Creation Date from type string to datetime before we could do some operations.

The AMI Creation Date string looks like 2019-09-18T07:34:34.000Z. To convert this we need to use the strptime function from the datetime.datetime library.

Continue reading Convert boto3 AMI Creation Date from string to Python datetime

How to connect Logitech K380 Keyboard to Windows 11

The Logitech K380 Keyboard is one of my favorite devices. It gives me fewer wires to worry about by connecting wirelessly via Bluetooth. It can also easily switch between 3 devices by pressing the F1, F2, or F3 keys.

In this article, we will do a step-by-step guide on how to connect your Logitech K380 to Windows 11.


Instruction to Connect Logitech K380 Keyboard to Windows 11

#1

Open Windows Settings by clicking the Start Menu, and searching for ‘settings’. Then click on Settings.


#2

On the left sidebar of the Settings window, click on Bluetooth & devices.

Continue reading How to connect Logitech K380 Keyboard to Windows 11

How to connect Logitech K380 to Mac (with Screenshots)

The Logitech K380 Bluetooth Keyboard is so far my most used keyboard. I like how I can switch connection to 3 different computers with a press of the button.

I have connected my Logitech K380 to my Windows laptop and also to a Raspberry Pi.

In this tutorial, I connected the K380 keyboard to a Mac computer. What I used is a Macbook Air, but the tutorial should be the same even if you are using a Macbook Pro or an iMac with an M1 or Intel processor.

Logtech K380 Keyboard

Step-by-Step Instructions on how to connect Logitech K380 Bluetooth Keyboard to Mac

#1

Click on the Apple Menu and select System Preferences…

Continue reading How to connect Logitech K380 to Mac (with Screenshots)

How to connect Logitech M350 Pebble mouse to Windows 11

The Logitech M350 Pebble is so far the best mouse that I have used, and I have used a lot of mouse in my 30 years of existence.

I like it because it is wireless, lightweight, quiet, responds well and does not have ribs in the scroll bar. I can use the mouse the whole day without my hands or fingers getting numb.

Also, it has been a year since I bought the mouse and I have not even changed the battery yet.

When I first bought the Logitech M350 Pebble I got confused because it says that it has Bluetooth connection. But when I saw the wireless USB dongle, I thought I got tricked. As it turns out this mouse has both – a (1) wireless USB dongle mode and a (2) Bluetooth mode.

Continue reading How to connect Logitech M350 Pebble mouse to Windows 11

How to connect Raspberry Pi to Bluetooth Keyboard

Follow the steps below to connect your Bluetooth Keyboard or Mouse to your Raspberry Pi.

I’m using a Logitech K380 on the examples below since that is my Bluetooth keyboard. But you can follow the same steps if you are using a different Bluetooth keyboard or device, such as a Bluetooth mouse.

Continue reading How to connect Raspberry Pi to Bluetooth Keyboard

How to Fix Typing Wrong Keyboard Characters in Raspberry Pi

The first time I used a Raspberry Pi years ago, I got frustrated that I could not connect to the WiFi Network. So I tested on the text editor if I am typing the correct password. As it turns out, pressing the backslash (\) on the keyboard will type the hashtag symbol (#), and if I press Shift + 2 will type double-quotes (") instead of At sign (@).

The reason for the incorrect characters being typed is by default the Raspberry Pi is set to use a UK-based keyboard layout. To correct this, we need to reconfigure the keyboard layout to the ones we are using.

In my case, I am using a US-based keyboard layout. In the tutorial below that is what I am going to use. You can select the keyboard layout that you are using.

There are several ways to update the Keyboard Layout in a Raspberry Pi, you may choose which one you prefer on the list below.

Continue reading How to Fix Typing Wrong Keyboard Characters in Raspberry Pi

How to change the System Font and Icon Size of Raspberry Pi Desktop

Depending on the screen size or the usage of the Raspberry Pi, I usually tweak the font size and icon size.

If I am teaching or recording videos, I want the icon and font size to be large. If I am blogging, then I want them to be medium size. If I am using a small resolution screen then I want to change the icon and font size to a smaller proportion.

Appearance Settings

Luckily, Raspberry Pi has a Set Defaults icon for different screen sizes which makes it quick for me to change the sizes.

To change the system icon and font size of the Raspberry Pi head over to Appearance Settings and tweak the configuration there.

If you need guidance or instructions on how to navigate the settings then follow the tutorial below.

Continue reading How to change the System Font and Icon Size of Raspberry Pi Desktop