AWS SDK - Part 1
AWS provides three types of interfaces to interact with it. The first one is the web UI or also called the console(This is actually the web UI and not a cli). However, sometimes doing tasks via the web UI might not be convenient like automation pipelines. Thus we also have the AWS CLI which via Secret Access Key provides the opportunity to interact via command line tool and extract or pass information in json or yaml format. Lastly, AWS also provides us with the SDK/API interface on which the AWS CLI is written to interact.
Soo what we can do with the AWS SDK ? Well many things. Some common use cases might be:
- Connecting to AWS Native services like DynamoDB, S3 or SQS
- You need to use the SDK as those services were developed by AWS and the interface to interact with them is within the SDK.
- Writing scripts to automate tasks like reports for resources you have in AWS
- For example how many Virtual Machines do I have in my account based on tags
- Automating things like dynamically adding an IP address into a Security Group
- Although not really popular, but you can also use the SDK as Infrastructure as Code
- Create/Update/Delete resources and follow their state
Supported languages:
- C++
- Go
- Java
- JavaScript
- Kotlin
- .NET
- Node.js
- PHP
- Python
- Ruby
- Rust
- Swift
Let’s create an example simple application which connects to AWS SQS from Python.
Step 1
Install AWS-CLI and add your access keys which have the correct IAM permissions to utilise SQS. If you have not done this you can follow:
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html - To install AWS CLI
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html - To configure it
Step 2
Install “boto3” via pip command. pip3 install boto3 and import the package.
Step 3
Write our code:
As we can see with just a few lines we can get a message from our queue
Ok, but how to do we create messages and how to handle our format ? Well the message body is just a text, so you can pass json, yaml or even plain text.
Well this is quite simple again. As we can see in the example, we are just sending 8 char long strings constantly until we stop the python script. Just here instead of calling the receive message method we are calling the send message with an argument containing our message content as a string.
Please keep in mind that this is just a very simple example we can begin to interact with the SDK. In Real production environment you will have much more complexity. Stay tunned for part 2 !
2022-10-22 08:59:42 Cloud, AWS, SDK, Python