<<<Publish WeeWX to S3>>>

Enable S3 access from Rasberry Pi

Once you have created your S3 bucket and IAM account, the next step is to allow access from your Rasberry Pi. Inially we are going to setup command line access.

Install the Python3 libraries

Make sure you do this correctly and do not inadvertantly install the Python2 libraries, if you inadvertantly install the Python2 libraries then you may 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

The following steps will take you through the process of setting up programatic access to the S3 bucket in AWS

Use the values of the Access Key ID and Secret Access Key that you recorded earlier which will allow access to your S3 bucket

Note: that you have to set the permissions of these 2 files such that only the owner can see them, this is because they contain user connectivity informartion

pi@raspberrypi:~ $ vi ~/.aws/credentials
[weewx]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key =  wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

pi@raspberrypi:~ $ vi ~/.aws/config
[profile weewx]
region = us-east-1
output = json

pi@raspberrypi:~ $ chmod 600 ~/.aws/credentials
pi@raspberrypi:~ $ chmod 600 ~/.aws/config
    

Now that we have set the AWS credentials we should be able to query our S3 bucket

pi@raspberrypi:~ $ aws s3 ls --profile weewx

An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied

pi@raspberrypi:~ $ aws s3 ls s3://mikes-weewx --profile weewx
    

What Just Happened?

The two files are the configuration files that awscli reads when accessing your AWS environment. We created a profile called weewx that uses the IAM user we created earlier and this user is granted the ability to delete, get, list and put on our S3 bucket

So the first ls command failed because we did not provide the bucket name, which meant we were scanning the entire environment and as we do not have the necessary privilges for that we got an error

The second command succeeded because we told it which bucket to look in, the one we granted privileges on, but this returned nothing as there is nothing in our S3 bucket yet

Populating the S3 Bucket

So, lets put a HTML file into our bucket so that we can see it from a WEB browser

First lets create a Hello World HTML file

pi@raspberrypi:~ $ vi index.html
<html>
  <header>
    <title>This is title</title>
  </header>
  <body>
    Hello world
  </body>
</html>
    

Then copy it up to our new S3 Bucket

pi@raspberrypi:~ $ aws s3 cp index.html s3://mikes-weewx/index.html --profile weewx
upload: ./index.html to s3://mikes-weewx/index.html
    

Now you should be able to see index.html in your console

SonicWall

Select this file and click on the Object URL

SonicWall

This will give you an Access Denied error

This is because that, although we have given Public access capabilities to our S3 bucket, we have not given public access to any of the objects in the bucket

So copy the file again, this time granting public access

pi@raspberrypi:~ $ aws s3 cp index.html s3://mikes-weewx/index.html --acl public-read --profile weewx
upload: ./index.html to s3://mikes-weewx/index.html
    

Refresh the HTML page in your web browser and you should now see

Hello world