Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# dependencies
node_modules
.pnp
.pnp.js

# testing
coverage

# production
build

# misc
.aws-sam
samconfig.toml
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

assets
preview_build
.DS_Store
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const AWS = require('aws-sdk');
const ddb = new AWS.DynamoDB.DocumentClient();
const table_name = process.env.TABLE_NAME;

exports.handler = async (event, context) => {
console.log(event);
const connection_id = event.requestContext.connectionId;
const domain_name = event.requestContext.domainName;
const stage = event.requestContext.stage;
await add_connection_id(connection_id, domain_name, stage);
return {
statusCode: 200
};
};

async function add_connection_id(connection_id, domain_name, stage) {
console.log(connection_id);
await ddb.put({
TableName: table_name,
Item: {
connectionId: connection_id,
domainName: domain_name,
stage: stage
}
}).promise();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const AWS = require('aws-sdk');
const ddb = new AWS.DynamoDB.DocumentClient();
const table_name = process.env.TABLE_NAME;

exports.handler = async (event, context) => {
const connection_id = event.requestContext.connectionId;
await delete_connection_id(connection_id);
return {
statusCode: 200
};
};

async function delete_connection_id(connection_id) {
await ddb.delete({
TableName: table_name,
Key: {
connectionId: connection_id
}
}).promise();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const AWS = require("aws-sdk");
const ddb_client = new AWS.DynamoDB.DocumentClient({
region: process.env.AWS_REGION,
});
const apigw_management_api_client = new AWS.ApiGatewayManagementApi({
endpoint: process.env.API_URL,
});

const table_name = process.env.TABLE_NAME;

exports.handler = async (event, context) => {
console.log(event);
console.log(`Endpoint URL: ${process.env.API_URL}`);

const connection_id = event.requestContext.connectionId;

try {
console.log(`posting to connection ${connection_id}`);
await apigw_management_api_client
.postToConnection({
ConnectionId: connection_id,
Data: "Hi from Lambda!",
// Data: JSON.stringify(event),
})
.promise();
} catch (e) {
console.log(`excetion caught: ${e}`);
if (e.statusCode === 410) {
console.log(`Found stale connection, deleting ${connection_id}`);
await ddb_client
.delete({
TableName: table_name,
Key: {
connectionId: connection_id,
},
})
.promise();
} else {
throw e;
}
}

console.log("Exiting the function");
return {
body: JSON.stringify({ connectionId: connection_id }),
statusCode: 200,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Description: >

Globals:
Function:
Runtime: python3.9
Runtime: nodejs14.x
MemorySize: 128
Timeout: 15

Expand Down Expand Up @@ -57,11 +57,27 @@ Resources:
Description: Disconnect Integration
IntegrationType: AWS_PROXY
IntegrationUri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${OnDisconnectFunction.Arn}/invocations
OnMsgRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref WebSocketAPI
RouteKey: onMsg
AuthorizationType: NONE
OperationName: OnMsgRoute
Target: !Join [ '/', ['integrations', !Ref OnMsgInteg]]
OnMsgInteg:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref WebSocketAPI
Description: OnMsg Integration
IntegrationType: AWS_PROXY
IntegrationUri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${OnMsgFunction.Arn}/invocations
Deployment:
Type: AWS::ApiGatewayV2::Deployment
DependsOn:
- ConnectRoute
- DisconnectRoute
- OnMsgRoute
Properties:
ApiId: !Ref WebSocketAPI
Stage:
Expand Down Expand Up @@ -92,8 +108,8 @@ Resources:
OnConnectFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: handlers/websocketHandlers/onConnect/
Handler: app.handler
CodeUri: lambda_functions/websocket/onConnect/
Handler: func.handler
Environment:
Variables:
TABLE_NAME: !Ref ConnectionsTable
Expand All @@ -111,8 +127,8 @@ Resources:
OnDisconnectFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: handlers/websocketHandlers/onDisconnect/
Handler: app.handler
CodeUri: lambda_functions/websocket/onDisconnect/
Handler: func.handler
Environment:
Variables:
TABLE_NAME: !Ref ConnectionsTable
Expand All @@ -127,11 +143,11 @@ Resources:
Action: lambda:InvokeFunction
FunctionName: !Ref OnDisconnectFunction
Principal: apigateway.amazonaws.com
ReportProgressFunction:
OnMsgFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: handlers/websocketHandlers/reportProgress/
Handler: app.handler
CodeUri: lambda_functions/websocket/onMsg/
Handler: func.handler
Environment:
Variables:
TABLE_NAME: !Ref ConnectionsTable
Expand All @@ -145,6 +161,15 @@ Resources:
- 'execute-api:ManageConnections'
Resource:
- !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${WebSocketAPI}/*'
OnMsgPermission:
Type: AWS::Lambda::Permission
DependsOn:
- WebSocketAPI
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref OnMsgFunction
Principal: apigateway.amazonaws.com


Outputs:
WebSocketURL:
Expand Down
70 changes: 70 additions & 0 deletions progress-tracking-app/react-frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Loading