AutoIt
AutoIt
Call an AWS Lambda Function
See more AWS Misc Examples
Demonstrates how to call an AWS Lambda function.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oRest = ObjCreate("Chilkat.Rest")
; Connect to the Amazon AWS REST server.
; such as https://email.us-west-2.amazonaws.com/
Local $bTls = True
Local $iPort = 443
Local $bAutoReconnect = True
; -------------------------------------------------------------------------------------------
; Note: The source of the lambda function (hosted on AWS) is shown at the bottom of this page.
; --------------------------------------------------------------------------------------------
; If your lambda function URL is: https://itwxyj3vd6gjtaerbfqnfccs2e0fplzh.lambda-url.us-west-2.on.aws/
; then use just the domain part here:
$bSuccess = $oRest.Connect("itwxyj3vd6gjtaerbfqnfccs2e0fplzh.lambda-url.us-west-2.on.aws",$iPort,$bTls,$bAutoReconnect)
; Provide AWS credentials for the REST call.
$oAuthAws = ObjCreate("Chilkat.AuthAws")
$oAuthAws.AccessKey = "AWS_ACCESS_KEY"
$oAuthAws.SecretKey = "AWS_SECRET_KEY"
; the region should match our domain above..
$oAuthAws.Region = "us-west-2"
$oAuthAws.ServiceName = "lambda"
$oRest.SetAuthAws($oAuthAws)
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("name","Benny")
$oRest.AddHeader("Content-Type","application/json")
$oSbRequestBody = ObjCreate("Chilkat.StringBuilder")
$oJson.EmitSb($oSbRequestBody)
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oRest.FullRequestSb("POST","/",$oSbRequestBody,$oSbResponseBody)
If ($bSuccess = False) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
Local $iStatusCode = $oRest.ResponseStatusCode
If ($iStatusCode >= 400) Then
ConsoleWrite("Response Status Code: " & $iStatusCode & @CRLF)
ConsoleWrite("Response Body: " & $oSbResponseBody.GetAsString() & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oSbResponseBody.GetAsString() & @CRLF)