Skip to content

Commit

Permalink
fix: remove support for LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Oct 13, 2023
1 parent 41b6d90 commit f1166d0
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 382 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ npm ci
npx cdk deploy
```

## Support for the MQTT Sample

Because the sample is not using the shadow, some manual work is needed to make
it work:

1. Create a thing type `rgb-light` (they cannot be created using
CloudFormation).
1. Assign the thing type `rgb-light` to the thing which should act as a light
bulb.

## Authentication

For changing the state of light bulbs, create a Thing attribute named `code` and
Expand Down
1 change: 0 additions & 1 deletion cdk/BackendLambdas.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ type BackendLambdas = {
publishSummaries: PackedLambda
onNewNetworkSurvey: PackedLambda
onNetworkSurveyLocated: PackedLambda
lightbulbPing: PackedLambda
}
1 change: 0 additions & 1 deletion cdk/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ new BackendApp({
publishSummaries: await pack('publishSummaries'),
onNewNetworkSurvey: await pack('onNewNetworkSurvey'),
onNetworkSurveyLocated: await pack('onNetworkSurveyLocated'),
lightbulbPing: await pack('lightbulbPing'),
},
layer: await packLayer({
id: 'baseLayer',
Expand Down
25 changes: 14 additions & 11 deletions cdk/packLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ export const packLayer = async ({

await mkdir(nodejsDir, { recursive: true })

const depsToBeInstalled = dependencies.reduce((resolved, dep) => {
const resolvedDependency = deps[dep] ?? devDeps[dep]
if (resolvedDependency === undefined)
throw new Error(
`Could not resolve dependency "${dep}" in ${packageJsonFile}!`,
)
return {
...resolved,
[dep]: resolvedDependency,
}
}, {} as Record<string, string>)
const depsToBeInstalled = dependencies.reduce(
(resolved, dep) => {
const resolvedDependency = deps[dep] ?? devDeps[dep]
if (resolvedDependency === undefined)
throw new Error(
`Could not resolve dependency "${dep}" in ${packageJsonFile}!`,
)
return {
...resolved,
[dep]: resolvedDependency,
}
},
{} as Record<string, string>,
)

await writeFile(
path.join(nodejsDir, 'package.json'),
Expand Down
21 changes: 0 additions & 21 deletions cdk/resources/LambdaLogGroup.ts

This file was deleted.

117 changes: 0 additions & 117 deletions cdk/resources/LightbulbThings.ts

This file was deleted.

5 changes: 2 additions & 3 deletions cdk/resources/PublishSummaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
aws_lambda as Lambda,
Duration,
Stack,
aws_logs as Logs,
} from 'aws-cdk-lib'
import type { IPrincipal } from 'aws-cdk-lib/aws-iam/index.js'
import { Construct } from 'constructs'
import type { PackedLambda } from '../backend.js'
import { LambdaLogGroup } from '../resources/LambdaLogGroup.js'
import type { WebsocketAPI } from './WebsocketAPI.js'

/**
Expand Down Expand Up @@ -78,10 +78,9 @@ export class PublishSummaries extends Construct {
resources: ['*'],
}),
],
logRetention: Logs.RetentionDays.ONE_WEEK,
})

new LambdaLogGroup(this, 'Logs', lambda)

websocketAPI.connectionsTable.grantFullAccess(lambda)

const rule = new Events.Rule(this, 'Rule', {
Expand Down
12 changes: 3 additions & 9 deletions cdk/resources/ResolveCellLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
aws_iot as IoT,
aws_lambda as Lambda,
Stack,
aws_logs as Logs,
} from 'aws-cdk-lib'
import { Construct } from 'constructs'
import type { PackedLambda } from '../backend.js'
import { LambdaLogGroup } from '../resources/LambdaLogGroup.js'
import type { WebsocketAPI } from './WebsocketAPI.js'

export class ResolveCellLocation extends Construct {
Expand Down Expand Up @@ -66,11 +66,10 @@ export class ResolveCellLocation extends Construct {
resources: ['*'],
}),
],
logRetention: Logs.RetentionDays.ONE_WEEK,
},
)

new LambdaLogGroup(this, 'resolveCellLocationLogs', resolveCellLocation)

websocketAPI.connectionsTable.grantFullAccess(resolveCellLocation)

const resolveCellLocationRuleRole = new IAM.Role(
Expand Down Expand Up @@ -167,16 +166,11 @@ export class ResolveCellLocation extends Construct {
}),
],
layers: [baseLayer],
logRetention: Logs.RetentionDays.ONE_WEEK,
},
)
websocketAPI.connectionsTable.grantFullAccess(onCellGeoLocationResolved)

new LambdaLogGroup(
this,
'onCellGeoLocationResolvedLogGroup',
onCellGeoLocationResolved,
)

const publishCellGeolocationSuccessEventsRule = new Events.Rule(
this,
'publishCellGeolocationSuccessEventsRule',
Expand Down
12 changes: 3 additions & 9 deletions cdk/resources/ResolveNetworkSurveyGeoLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
aws_lambda as Lambda,
aws_lambda_event_sources as LambdaEvents,
Stack,
aws_logs as Logs,
} from 'aws-cdk-lib'
import { Construct } from 'constructs'
import type { PackedLambda } from '../backend'
import { LambdaLogGroup } from './LambdaLogGroup.js'
import type { WebsocketAPI } from './WebsocketAPI'

/**
Expand Down Expand Up @@ -71,10 +71,9 @@ export class ResolveNetworkSurveyGeoLocation extends Construct {
resources: ['*'],
}),
],
logRetention: Logs.RetentionDays.ONE_WEEK,
})

new LambdaLogGroup(this, 'onNewNetworkSurveyLogs', onNewNetworkSurvey)

websocketAPI.connectionsTable.grantFullAccess(onNewNetworkSurvey)

onNewNetworkSurvey.addEventSource(
Expand Down Expand Up @@ -118,17 +117,12 @@ export class ResolveNetworkSurveyGeoLocation extends Construct {
}),
],
layers: [baseLayer],
logRetention: Logs.RetentionDays.ONE_WEEK,
},
)
websocketAPI.connectionsTable.grantFullAccess(onNetworkSurveyLocated)
surveysTable.grantReadData(onNetworkSurveyLocated)

new LambdaLogGroup(
this,
'onNetworkSurveyLocatedLogGroup',
onNetworkSurveyLocated,
)

const publishNetworkSurveyGeolocationSuccessEventsRule = new Events.Rule(
this,
'publishNetworkSurveyGeolocationSuccessEventsRule',
Expand Down
30 changes: 5 additions & 25 deletions cdk/resources/WebsocketAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
aws_lambda as Lambda,
RemovalPolicy,
Stack,
aws_logs as Logs,
} from 'aws-cdk-lib'
import { Construct } from 'constructs'
import type { PackedLambda } from '../backend.js'
import { LambdaLogGroup } from '../resources/LambdaLogGroup.js'

export class WebsocketAPI extends Construct {
public readonly websocketURI: string
Expand Down Expand Up @@ -82,10 +82,10 @@ export class WebsocketAPI extends Construct {
},
initialPolicy: [],
layers: [baseLayer],
logRetention: Logs.RetentionDays.ONE_WEEK,
})
this.connectionsTable.grantWriteData(onConnect)

new LambdaLogGroup(this, 'onConnectLogs', onConnect)
const connectIntegration = new ApiGateway.CfnIntegration(
this,
'connectIntegration',
Expand Down Expand Up @@ -117,27 +117,12 @@ export class WebsocketAPI extends Construct {
environment: {
VERSION: this.node.tryGetContext('version'),
CONNECTIONS_TABLE_NAME: this.connectionsTable.tableName,
WEBSOCKET_MANAGEMENT_API_URL: this.websocketManagementAPIURL,
},
initialPolicy: [
new IAM.PolicyStatement({
actions: ['iot:DescribeThing'],
resources: ['*'],
}),
new IAM.PolicyStatement({
actions: ['iot:Publish'],
resources: ['arn:aws:iot:*:*:topic/*/light-bulb/*'],
}),
new IAM.PolicyStatement({
actions: ['execute-api:ManageConnections'],
resources: [this.websocketAPIArn],
}),
],
layers: [baseLayer],
logRetention: Logs.RetentionDays.ONE_WEEK,
})
this.connectionsTable.grantReadWriteData(onMessage)

new LambdaLogGroup(this, 'onMessageLogs', onMessage)
const sendMessageIntegration = new ApiGateway.CfnIntegration(
this,
'sendMessageIntegration',
Expand Down Expand Up @@ -172,10 +157,10 @@ export class WebsocketAPI extends Construct {
},
initialPolicy: [],
layers: [baseLayer],
logRetention: Logs.RetentionDays.ONE_WEEK,
})
this.connectionsTable.grantWriteData(onDisconnect)

new LambdaLogGroup(this, 'onDisconnectLogs', onDisconnect)
const disconnectIntegration = new ApiGateway.CfnIntegration(
this,
'disconnectIntegration',
Expand Down Expand Up @@ -244,17 +229,12 @@ export class WebsocketAPI extends Construct {
}),
],
layers: [baseLayer],
logRetention: Logs.RetentionDays.ONE_WEEK,
},
)

this.connectionsTable.grantReadWriteData(publishToWebsocketClients)

new LambdaLogGroup(
this,
'publishToWebsocketClientsLogs',
publishToWebsocketClients,
)

const publishToWebsocketClientsRuleRole = new IAM.Role(
this,
'publishToWebsocketClientsRuleRole',
Expand Down
Loading

0 comments on commit f1166d0

Please sign in to comment.