Part 5 - Deploy to AWS


In the last part, we are going to deploy our application to your AWS account.

Prepare to package

Before we can package, we need to instruct SAM to exclude .aws-sam directory from our package. SAM is using npm pack to package each of the Lambdas. To exclude the directory create a .npmignore file and add .aws-sam to it:

touch .npmignore
echo '.aws-sam' >> .npmignore

Create a new s3 bucket to host our package:

aws s3api create-bucket --bucket iot-mqless

You must use a unique name (globally) for a bucket, so pick a different bucket name for your bucket.

Build and Package

Build and package our application:

sam build
sam package --s3-bucket iot-mqless --output-template-file packaged.yaml

Change the bucket name to your bucket name.

It can take a few minutes to upload the template to s3.

Deploying the package

Finally, let’s deploy our application:

sam deploy --template-file packaged.yaml --stack-name iot-mqless --capabilities CAPABILITY_IAM


Let’s first define an environment variable with endpoint of the remote MQLess you installed on AWS EC2 machine:


Let’s record some temperatures:

curl --data '{"temperature":25}' $MQLESS_ENDPOINT/send/Device/G2D1/RecordTemperature
curl --data '{"temperature":28}' $MQLESS_ENDPOINT/send/Device/G2D2/RecordTemperature

Let’s track them in the group:

curl --data '{"deviceId":"G2D1"}' $MQLESS_ENDPOINT/send/DeviceGroup/G2/RequestTrackDevice
curl --data '{"deviceId":"G2D2"}' $MQLESS_ENDPOINT/send/DeviceGroup/G2/RequestTrackDevice

And finally request all temperatures:

curl --data '{}' $MQLESS_ENDPOINT/send/DeviceGroup/G2/RequestAllTemperatures