Skip to content

Commit

Permalink
Adding cognito and IOT
Browse files Browse the repository at this point in the history
  • Loading branch information
astuyve committed Apr 18, 2019
1 parent 5bf1863 commit 85590e5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 20 deletions.
51 changes: 33 additions & 18 deletions globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ declare module '*.json' {
}

export interface AlexaSmartHomeEvent {
header: { [name: string]: string },
header: { [name: string]: string }
payload: {
switchControlAction: string,
switchControlAction: string
appliance: {
additionalApplianceDetails: { [name: string]: string },
applianceId: string,
applianceId: string
},
accessToken: string
}
}

export interface AlexaSkillEvent {
version: string,
session: AlexaSkillSession,
context: AlexaSkillContext,
session: AlexaSkillSession
context: AlexaSkillContext


}

export interface AlexaSkillSession {
new: boolean,
sessionId: string,
sessionId: string
application: {
applicationId: string
},
Expand All @@ -38,36 +38,51 @@ export interface AlexaSkillSession {
export interface AlexaSkillContext {
System: {
device: {
deviceId: string,
deviceId: string
supportedInterfaces: {
AudioPlayer: any
}
},
application: {
applicationId: string
},
user: AlexaSkillUser,
apiEndpoint: string,
user: AlexaSkillUser
apiEndpoint: string
apiAccessToken: string
},
AudioPlayer: {
playerActivity: string,
token: string,
offsetInMilliseconds: number,
playerActivity: string
token: string
offsetInMilliseconds: number
}
}

export interface AlexaSkillUser {
userId: string,
accessToken: string,
userId: string
accessToken: string
permissions: {
consentToken: string
}
}

export interface AlexaSkillRequest {
type: string,
requestId: string,
timestamp: string,
locale: string,
type: string
requestId: string
timestamp: string
locale: string
}

export interface CloudWatchEvent {
version: string
id: string
"detail-type": string
source: string
account: string
time: string,
region: string,
resources: string[],
detail: {
"instance-id": string,
state: string
}
}
16 changes: 16 additions & 0 deletions lib/events/aws/cloud-watch-event-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "0",
"id": "6a7e8feb-b491-4cf7-a9f1-bf3703467718",
"detail-type": "EC2 Instance State-change Notification",
"source": "aws.ec2",
"account": "111122223333",
"time": "2017-12-22T18:43:48Z",
"region": "us-west-1",
"resources": [
"arn:aws:ec2:us-west-1:123456789012:instance/ i-1234567890abcdef0"
],
"detail": {
"instance-id": " i-1234567890abcdef0",
"state": "terminated"
}
}
17 changes: 17 additions & 0 deletions lib/events/aws/cognito-user-pool-event-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": 2,
"triggerSource": "string",
"region": "us-east-1",
"userPoolId": "abcd123",
"userName": "myNameIsAJ",
"callerContext": {
"awsSdkVersion": "1",
"clientId": "abc1234"
},
"request": {
"userAttributes": {
"string": "string"
}
},
"response": {}
}
9 changes: 7 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { merge, cloneDeep } from 'lodash'
import { APIGatewayEvent, ScheduledEvent, S3Event, KinesisStreamEvent, DynamoDBStreamEvent, SQSEvent, SNSEvent, CloudWatchLogsEvent } from 'aws-lambda'
import { AlexaSmartHomeEvent, AlexaSkillEvent } from '../globals'
import { APIGatewayEvent, ScheduledEvent, S3Event, KinesisStreamEvent, DynamoDBStreamEvent, SQSEvent, SNSEvent, CloudWatchLogsEvent, CognitoUserPoolEvent } from 'aws-lambda'
import { AlexaSmartHomeEvent, AlexaSkillEvent, CloudWatchEvent } from '../globals'
import { GeneratedEvent } from './generatedEvent'
import snsTemplate from './events/aws/sns-template.json'
import sqsTemplate from './events/aws/sqs-template.json'
Expand All @@ -12,6 +12,8 @@ import dynamoTemplate from './events/aws/dynamo-stream-event-template.json'
import cloudwatchLogsEventTemplate from './events/aws/cloudwatch-logs-event-template.json'
import alexaSmartHomeEventTemplate from './events/aws/alexa-smart-home-event-template.json'
import alexaSkillEventTemplate from './events/aws/alexa-skill-event-template.json'
import cloudWatchEventTemplate from './events/aws/cloud-watch-event-template.json'
import cognitoUserPoolEventTemplate from './events/aws/cognito-user-pool-event-template.json'

const dictionary: any = {
'aws:sns': snsTemplate as SNSEvent,
Expand All @@ -24,6 +26,9 @@ const dictionary: any = {
'aws:cloudwatchLogEvent': cloudwatchLogsEventTemplate as CloudWatchLogsEvent,
'aws:alexaSmartHomeEvent': alexaSmartHomeEventTemplate as AlexaSmartHomeEvent,
'aws:alexaSkillEvent': alexaSkillEventTemplate as AlexaSkillEvent,
'aws:cloudWatchEvent': cloudWatchEventTemplate as CloudWatchEvent,
'aws:iot': {},
'aws:cognitoUserPool': cognitoUserPoolEventTemplate as CognitoUserPoolEvent,
}

export default function createEvent(eventType: string, body: any): GeneratedEvent {
Expand Down

0 comments on commit 85590e5

Please sign in to comment.