Using Pythonista and Boto3

The Apple iPhone and iPad have this wonderful Python development environment called Pythonista. If you can import a module using the Pythonista StaSh extension, then you can get working with boto3 in Pythonista.

Get and Launch StaSh

StaSh is a bash-like implementation that can run within Pythonista. There have been many improvements since its first release. To get and install StaSh, launch Pythonista and in the interactive console, execute the command

import requests as r; exec(r.get('http://bit.ly/get-stash').text)

Install boto3

Once StaSh is running, you can expand the console view and display the StaSh window.

The StaSh Console (image by author)
The StaSh Console (image by author)

Create the Credential and Config Files

Unfortunately, I haven’t been able to get the AWS CLI running within Pythonista, even though it is a Python application. That doesn’t mean all is lost, however. From within Pythonista, create a config file. Here is an example:

[default]
region = us-east-1
[preview]
sdb = true
[default]
aws_access_key_id = YOUR_ACCESS_KEY_ID
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
[~/Documents]$ cd ..
[~]$ mkdir .aws
[~]$ cd .aws
[~/.aws]$ mv ../Documents/config.txt config
[~/.aws]$ mv ../Documents/credentials.py credentials
[~/.aws]$ ls -l
config (50.0B ) 2020-10-10 01:31:53
credentials (116.0B ) 2020-10-10 01:31:08
[~/.aws]$

Try it out

This view illustrates a piece of sample Python code and the Pythonista console output.

Output from an AWS Service (image by author)
Output from an AWS Service (image by author)

Conclusion

Giving Pythonista the ability to execute the Python code you are working on to interface with AWS services makes it easier to write, test, and debug in the Pythonista interface. And since this isn’t something you are likely to do very often, you are likely to forget (which is why I wrote this article — I forgot and needed to update my secret key.)

References

Boto3 Credentials

About the Author

Chris is a highly-skilled Information Technology, AWS Cloud, Training and Security Professional bringing cloud, security, training, and process engineering leadership to simplify and deliver high-quality products. He is the co-author of seven books and author of more than 70 articles and book chapters in technical, management, and information security publications. His extensive technology, information security, and training experience make him a key resource who can help companies through technical challenges. Chris is a member of the AWS Community Builder Program.

Copyright

This article is Copyright © 2020, Chris Hare.

Chris is the co-author of seven books and author of more than 70 articles and book chapters in technical, management, and information security publications.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store