IOT Device Simulation using Lambda and S3
Sensor.py => Holds the code for generating sensor output and offloading into Aggregator.
Lambda.py => AWS Lambda which acts as an Aggregator
Create S3 bucket:
- Go to S3 buckets module in AWS console.
- Click on "Create Bucket"
- Enter bucket name, for example:scalable-computing-project4.
- Create the bucket with default settings.
Create Lambda:
- Navigate to the AWS Lambda console. Click "Create New Function"
- Create a blank template
- Copy code from
fogToCloud.pyand paste in the lambda handler - Create Function.
- Go to Identity access management -> Roles
- Search for the function name.
- Click "Attach Policy"
- Add S3 bucket policy.
Add Trigger to Lambda:
- Click on "Add Trigger"
- Select S3 from the "Select Trigger" dopdown.
- Select the Bucket you created.
- Click on add
Create S3 bucket for the aggregator:
- Go to S3 buckets module in AWS console.
- Click on "Create Bucket"
- Enter bucket name, for example: aggregator.
- Create the bucket with default settings.
Create Lambda:
- Navigate to the AWS Lambda console. Click "Create New Function"
- Create a blank template
- Copy code from aggregatorToFog.py and paste in the lambda handler.
Replace the sourceBucketName with the name of the bucket you just created, "aggregator" in our case.
Replace the destBucketName with the name of the fog bucket that you created, "scalable-computing-project4" in our case. - Create Function and name it "aggregatorToFog".
Add Trigger to Lambda:
- Click on "Add Trigger"
- Select S3 from the "Select Trigger" dropdown.
- Select the Bucket "aggregator" you just created.
- Click on add
- Create new python files for each of the sensors viz. Temperature, Glucose and Pedometer and paste their corresponding codes from the repo.
- Open the command prompt and navigate to the folder/s containing the defined sensors.
- Execute a sensor using simple python command and provide as a command line argument a number to simulate the initial level of battery that the particular sensor has at the time of execution.