Templates/Blueprints/SNSToSQS/snstosqs.ps1.txt

# PowerShell script file to be executed as a AWS Lambda function.
#
# When executing in Lambda the following variables will be predefined.
# $LambdaInput - A PSObject that contains the Lambda function input data.
# $LambdaContext - An Amazon.Lambda.Core.ILambdaContext object that contains information about the currently running Lambda environment.
#
# The last item in the PowerShell pipeline will be returned as the result of the Lambda function.
#
# To include PowerShell modules with your Lambda function, like the AWSPowerShell.NetCore module, add a "#Requires" statement
# indicating the module and version.
#
# This example demonstrates how to process an SNS Message that follows the process:
# SNS topic -> SQS Queue -> Lambda Function
 
#Requires -Modules @{ModuleName='AWSPowerShell.NetCore';ModuleVersion='3.3.428.0'}
 
# Uncomment to send the input event to CloudWatch Logs
# Write-Host (ConvertTo-Json -InputObject $LambdaInput -Compress -Depth 5)
 
foreach ($sqsRecord in $LambdaInput.Records)
{
    $snsRecord = ConvertFrom-Json -InputObject $sqsRecord.body
 
    # TODO: Add logic to process each SNS Record
    Write-Host $snsRecord.Message
}