Testing Our Serverless Slack Dicebot with Docker Locally
As we did in the Test hello_world step above, let's test our new events!
Remember to execute this command from the dicebot
directory, and not the first_function
or events
directory!
1
$ sam build -u && sam local invoke --event events/valid_roll_2d20.json
2
3
START RequestId: 210c2c8c-290e-1d47-64ff-bfc7b693234c Version: $LATEST
4
{'body': 'text=2d20'}
5
{'dice_roll': '2d20', 'results': [5, 7]}
6
END RequestId: 210c2c8c-290e-1d47-64ff-bfc7b693234c
7
REPORT RequestId: 210c2c8c-290e-1d47-64ff-bfc7b693234c Duration: 3.49 ms Bill
8
ed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 31 MB
9
{"statusCode":200,"body":"{\"response_type\": \"in_channel\", \"text\": \"[5, 7] = 1
10
2\", \"attachments\": [{\"text\": \"rolled 2d20\"}]}"}
11
12
$ sam build -u && sam local invoke --event events/invalid_roll_a.json
13
START RequestId: 5edfc030-edde-1961-4131-50d50ccb8d84 Version: $LATEST
14
{'body': 'text=a'}
15
END RequestId: 5edfc030-edde-1961-4131-50d50ccb8d84
16
REPORT RequestId: 5edfc030-edde-1961-4131-50d50ccb8d84 Duration: 2.91 ms Bill
17
ed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 31 MB
18
{"statusCode":400,"body":"{\"text\": \"invalid literal for int() with base 10: 'a'\"
19
}"}
Great, so the output shows a statusCode
of 200
was returned when valid input was given, and statusCode
of 400
when invalid input was given. If the function was to fail for a reason besides invalid input or output, we would expect to see a status code of 500
returned. If that happens, it means we messed up somewhere in our function code and need to check the log output!
Deploy dicebot to AWS#
This page is a preview of Create a Serverless Slackbot with AWS Lambda and Python