Create a new Role from a Policy with the following permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"dynamodb:CreateTable",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DescribeTable",
"dynamodb:GetShardIterator",
"dynamodb:GetRecords",
"dynamodb:ListStreams",
"dynamodb:Query",
"dynamodb:Scan"
],
"Resource": "*"
}
]
}
In AWS, create a DynamoDB table with a partition key of PartitionKey
.
In AWS, create a Lambda (using the new Role) from file #2.
For file #2, add the following environment variables to the Lambda:
SUPER_SECRET_PASSPHRASE
(some phrase people must text in order to be entered in to the raffle)BANNED_NUMBERS
(JSON list of phone numbers formatted["+15555555555","+15555555556"]
)DYNAMODB_REGION
(likeus-east-1
)DYNAMODB_ENDPOINT
(likehttps://dynamodb.us-east-1.amazonaws.com
)DYNAMODB_TABLE
In AWS, create a Lambda (using the new Role) from file #3.
For file #3, add the following environment variables to the Lambda:
DYNAMODB_REGION
(likeus-east-1
)DYNAMODB_ENDPOINT
(likehttps://dynamodb.us-east-1.amazonaws.com
)DYNAMODB_TABLE
TWILIO_ACCOUNT_SID
TWILIO_AUTH_TOKEN
TWILIO_SMS_FROM
(Twilio phone number formatted+15555555555
)NUM_WINNERS
(defaults to "10" if not set)
In AWS, create a new API Gateway. In the API, create the following:
- Create a new "POST" method with the "Integration type" of "Lambda Function" and point it to the Lambda for file #2
- Edit the "POST" method's "Integration Request"
- Under "Mapping Templates", add a "Content-Type" of
application/x-www-form-urlencoded
using the "General template" of "Method Request Passthrough"
- Under "Mapping Templates", add a "Content-Type" of
- Edit the "POST" method's "Method Response"
- Edit the
200
response so it has a "Content type" ofapplication/xml
- Edit the
- Edit the "POST" method's "Integration Request"
Last, under the "POST" method's "Integration Response", edit the 200
response. Under "Mapping Templates" of "Content-Type" of application/xml
with the following template:
#set($inputRoot = $input.path('$'))
$inputRoot.body
Deploy the new API Gateway.
In Twilio, create a phone number and set it up. Under "Messaging", select "Webhook" for when "A Message Comes In", select "POST", and enter the deployed API Gateway URL.
Users can now text the super secret passphrase to the phone number to be entered in to the raffle. When you are ready to close the raffle and have the winners randomly chosen, manually execute the Lambda created for file #3, which will close the raffle and text the winners.
A list of entries, with winners marked accordingly, can be found by viewing the items in the DynamoDB table for the raffle.