<<< Rasberry Pi Guides >>>
Install awscli onto Rasberry Pi
I bought a Rasberry Pi last year, with a view to moving my weather station software off of my main PC.
As I run my website from an AWS S3 bucket, I use awscli and boto3 as the api for the python calls to synchronise the pages and this requires the use of Python3 which in turn requires the use of WeeWX 4, see my other post to see how to setup Python3 as the default
This post documents the configuration of boto3 and awscli to facillitate the copying of files to S3 fdor presentation and the backup of the database for preservation.
Install the Python3 libraries
Make sure you do this correctly and do not inadvertantly install the Python2 libraries as directed in theWeeWX Guide
If you inadvertantly install the Python2 libraries then you will get errors relating to configobj
pi@raspberrypi:~ $ python -V Python 3.7.3 pi@raspberrypi: $ sudo pip3 install boto3 pi@raspberrypi: $ sudo pip3 install awscli
Now configure awscli
There are excellent guides on the AWS Website on how to do this
Because we are using Boto3 and awscli to copy files to S3, we have to confugure awscli before it can be used by the daemon
Use the values of the Access Key ID and Secret Access Key as shown here as this will allow the necessary files to be created, we will be enter the correcct values later
Note: We also set the values for su as this is the user who runs the daemon
pi@raspberrypi:~ $ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-east-1 Default output format [None]: json pi@raspberrypi:~ $ sudo aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-east-1 Default output format [None]: json
Configure aws credentials
Before the WeeWX extension can use boto3 through awscli, you have to configure the credentials file with the data necessary to connect to the S3 environment. The credentials that you use here should have restricted access to you S3 bucket only or you may be exposing your environment unintentionally
The config file should already be populated from the command earlier, note taht you region may well be different from that shown, but I use us-east-1 because it is the cheapest region
pi@raspberrypi:~ $ cd .aws pi@raspberrypi:~/.aws $ cat config [default] region = us-east-1 output = json
Now edit the credentials file, this is where you will be entering the awscli security credentials that will give the WeeWX S3 extension the necessary privileges to connect to the S3 bucket and upload files
The name between the square brackets [] is what goes in the WeeWX config file
pi@raspberrypi:~/.aws $ vi credentials [weewx-upload] aws_access_key_id=AKIAIOSFODNN7EXAMPLE aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Now you should be able to list the contents of you S3 environment
pi@raspberrypi:~/.aws $ aws s3 ls --profile weewx-upload 2019-01-30 08:14:24 archive.revittmk.aws.co.uk 2019-01-30 08:26:47 weather.revittmk.aws.co.uk 2018-07-16 10:05:10 db-freedom