I use the following curl command to publish some data from an IoT Thing to AWS's IoT Core service.
curl.exe --tlsv1.2 --cacert root-CA.pem --cert certificate.pem --key private.pem -X POST -d "$($Body)" "https://ats.iot.eu-west-1.amazonaws.com:8443/topics/example/1"
The command works perfectly, but I would like to leverage the features of the Invoke-WebRequest
commandlet. Unfortunately I cannot figure out how to rewrite the curl command, primarily because of the two certificates and key file.
What I have so far is:
# Set TLS to use version 1.2 (required by AWS)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Make the request
Invoke-WebRequest -Method POST -UseBasicParsing -Uri "https://ats.iot.eu-west-1.amazonaws.com:8443/topics/example/1" -Certificate (Get-PfxCertificate .\certificate.pem) -Body "Some example data!" -ContentType "application/json"
The output of the command above is:
Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channel.
How can I use the Key and the Root CA cert as I am in the CURL command?