Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

Latest commit

 

History

History
180 lines (138 loc) · 3.81 KB

AWS-Setup.md

File metadata and controls

180 lines (138 loc) · 3.81 KB

IAM

Role

Trusted entity type: AWS Service
Use case: Lambda
Permissions policies:

  1. Policy name: AdministratorAccess

Role name: whosthat

IoT Core

Thing

Thing name: whosthat
Device Shadow: No shadow
Policy: whosthat

Security Policy

Policy name: whosthat
Policy document:

  1. Policy Effect: Allow
    Policy Action: iot:Connect
    Policy Resource: *
  2. Policy Effect: Allow
    Policy Action: iot:Publish
    Policy Resource: *
  3. Policy Effect: Allow
    Policy Action: iot:Receive
    Policy Resource: *
  4. Policy Effect: Allow
    Policy Action: iot:Subscribe
    Policy Resource: *

Message Routing Rules

Rule name: whosthat
SQL version: 2016-03-23
SQL statement: SELECT * FROM "location"
Rule actions:

  1. Action: Lambda
    Lambda function: whosthat

Lambda

Function

Function name: whosthat
Runtime: Node.js 16.x
Architecture: x86_64
Execution role: Use an existing role
Existing role: whosthat

Triggers

  1. Source: AWS IoT (Custom IoT Rule)
    Rule name: whosthat
  2. Source: S3
    Bucket: whosthat
    Event type: All object create events
  3. Source: API Gateway
    Intent: Create a new API
    API type: HTTP API
    Security: Open
    API name: whosthat
    Cross-origin resource sharing (CORS): true

Code

distancediff.js
index.js

Test

  1. Event name: S3-Create
    Template: S3 Put
    Event JSON:
    {
    	"Records.0.s3.object.key": "8df4e168-c926-47b0-9e51-56ff408d41ee-1669106569684.jpg"
    }
  2. Event name: User-Location
    Event JSON:
    {
    	"user_id": "d8097ad2-fcfa-4846-a166-64ab94435ccf",
    	"location": {
    		"latitude": 1,
    		"longitude": 100
    	}
    }

Environment Variables

ts-lambda-whosthat/.env.example

S3

Bucket

Bucket name: whosthat
Object Ownership: ACLs enabled (Bucket owner preferred)
Block Public Access settings for this bucket: Disable all 5 checkboxes

Bucket policy

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Sid": "whosthat",
			"Effect": "Allow",
			"Principal": "*",
			"Action": ["s3:*"],
			"Resource": ["arn:aws:s3:::whosthat", "arn:aws:s3:::whosthat/*"]
		}
	]
}

Cross-origin resource sharing (CORS)

[
	{
		"AllowedHeaders": ["*"],
		"AllowedMethods": ["PUT", "POST", "DELETE", "GET"],
		"AllowedOrigins": ["*"],
		"ExposeHeaders": []
	}
]

API Gateway

Cross-Origin Resource Sharing

Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: *

Simple Notification Service

Topic

Type: Standard
Name: whosthat

Subscription

Topic ARN: whosthat
Protocol: Email
Endpoint: {Email Address}

DynamoDB

Tables

  1. Table name: areas
    Partition key: id
  2. Table name: cameras
    Partition key: id
  3. Table name: camera_feeds
    Partition key: id
  4. Table name: reports
    Partition key: id
  5. Table name: users
    Partition key: id
  6. Table name: users_areas
    Partition key: id
  7. Table name: user_locations
    Partition key: id