Connection to amazon server with certificate and key (.pem.crt ; .pem)


I'm trying to connect an app made in Mit App Inventor to an Amazon server with certificate and key (.pem.crt ; .pem).

With the example code from the Python documentation (HTTPS - AWS IoT Core) I was able to make a Post work, but I still couldn't with Mit App Inventor, I would like some help, it's for a final course conclusion work.

Basically it uses a certificate (certificate.pem.crt) and a key (key.pem) that I already have and sends a message to the server using a link (with endpoint and topic wherever it is written).

Part of the code in Python (which uses the requests library):
-# create and format values ​​for HTTPS request
publish_url = 'https://' + args.endpoint + ':8443/topics/' + args.topic + '?qos=1'
publish_msg = args.message.encode('utf-8')

-# make request
publish = requests.request('POST',
cert=[args.cert, args.key])

I would like some help on how to assemble this python request in Mit App Inventor.


Seems we need to make a web component url and POST request from the above.

Please show your relevant blocks on what you have so far ?

Thanks for your return

I've tried several ways, this was the last one.

If you can help me I would really appreciate it! To speed up because of time, my email is removed by mod, if we get the solution we will post the solution here.

Please no personal info on the community. I removed you mail address.

Ok, sorry about that.

You do not need the last block


What do you get as a responseContent in the Web1.GotText event ?

I removed the last block as you said, the print of the error :

Hmmm, not even getting close to a connection.

You say that with the details you have you can connect using python ?

Can you try with curl (the next tab on the page you linked to)

That syntax is easier (for me!) to convert to AI2 blocks code

Also just looking at the syntax for curl (and python) both seem to point to files as opposed the content of the files.....

I did it using Curl and it works too.

The certificate and key are in the same folder and the file name and path is placed in the command.

In Python:

If you replace the:

--cert certificate.pem.crt


-cert "-----BEGIN CERTIFICATE-----MIIDWj....."

and likewise with the private key

does it still work ?

There is a problem when placing due to the high number of characters in cmd.

Try this:

I also notice that the url you used in curl is slightly different to the one you showed earlier:

Is it sub or pub ?

I did as you said

but did not work

To facilitate the files are here:

They must be placed in the same folder where curl is.

Is pub.

Thanks for the files, I will try a few things...

Thank you very much for your attention!

To make it easier, could upload the files to the app and read the content of the files to put in the request, but I don't really know how to do it that way.

Well, I have tried just about every configuration known to man for a POST request, and they all return the same 1103 error.

I get the feeling that the url is just not connecting, and possibly the aws server is expecting some sort of TLS header.

Perhaps @ewpatton can shed some light.

We know your python command works, and the curl command too...

curl --tlsv1.2 \
--cacert AmazonRootCA1.pem \
--cert certificate.pem.crt \
--key private.pem.key \
--request POST \
--data "{ \"message\": \"Hello, world\" }"    \

If all else fails, then you may need to use an intermediate server to run the python/curl command and return the output.

Blocks - draggable

Thanks for the attempts, I hope he (@ewpatton) has a light.

Do you have any suggestions for an intermediate server?

If you want to run your own VPS then try IONOS @£1.20 per month, monthly contract (it may depend on where you are in the world)

Then setup php and curl and some bash scripts to connect the two.