AWS Service Configuration

This sample shows how to access services of the cloud provider Amazon Web Services (AWS) from the PLC using a GET request (required TwinCAT version: 3.1.4024.12). The REST API provides all the functionality that a user would have in the AWS management console. For example, virtual machines can be instantiated or configured using the AWS EC2 service.

The chapter AWS Signature Version 4 briefly touches on the background of the AWS signing function. For more information please refer to the AWS documentation.

As already described in the chapter URL redirects, the IoT driver does not evaluate URL redirects. Therefore, when accessing the local endpoint of an AWS data center, the exact address must always be specified. Again referring to the EC2 services sample, this means that a user cannot connect from TwinCAT to ec2.amazonaws.com but must directly provide the region in the link: ec2.eu-central-1.amazonaws.com.

A possible approach would be: Fetch all available regions via a location-independent AWS REST API function and extract the region endpoint for the desired region from it. This would have the advantage over static programming of the endpoint that changes in the endpoint URL of a region would not result in changes in the program code.

PROGRAM MAIN
VAR
    // trigger command execution for AWS Sig V4 samples
    bGetAWSSigV4                    : BOOL;

    fbHttpClientAWSSigV4            : FB_IotHttpClient :=(sHostName:='ec2.us-east-1.amazonaws.com',
                                    bKeepAlive:=FALSE, tConnectionTimeout:=T#10S);

    fbHttpGetAWSSigV4               : FB_TestHTTP_Get_AwsSigV4;
END_VAR
//init client parameters at startup
IF NOT fbHttpClientAWSSigV4.bConfigured THEN
    fbHttpClientAWSSigV4.nHostPort:=443;
    fbHttpClientAWSSigV4.stTLS.bNoServerCertCheck:=TRUE;
END_IF

IF fbHttpClientAWSSigV4.bConfigured THEN
    fbHttpGetAWSSigV4(bSend:= bGetAWSSigV4, fbClient:= fbHttpClientAWSSigV4);
END_IF

fbHttpClientAWSSigV4.Execute();