Wip backend (#4)

* feat: Add new API handlers for user, project, and task management; update package dependencies

* feat: Update .gitignore, add Lambda layer configuration, and refactor DynamoDB handlers to use AWS SDK v3

* feat: Update serverless configuration and refactor API handlers to improve error handling and response structure

* feat: Add Cognito user pool name parameter and update API handlers to include CORS headers

* feat: Update task and project ID formats, add populateSeedData function, and enhance user ID handling

* feat: Update image source paths to use S3 public URL for profile and task attachments
This commit was merged in pull request #4.
This commit is contained in:
2024-11-23 18:17:00 +02:00
committed by GitHub
parent ac8455ab3a
commit 11e61829f1
39 changed files with 5438 additions and 100 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
{
"name": "nodejs",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.699.0",
"@aws-sdk/lib-dynamodb": "^3.699.0",
"@types/uuid": "^10.0.0",
"uuid": "^11.0.3"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -5,18 +5,27 @@
"scripts": {
"infra:init": "cd terraform && AWS_PROFILE=default terraform init",
"infra:plan": "cd terraform && AWS_PROFILE=default terraform plan",
"infra:apply": "cd terraform && AWS_PROFILE=default terraform apply"
"infra:apply": "cd terraform && AWS_PROFILE=default terraform apply",
"infra:destroy": "cd terraform && AWS_PROFILE=default terraform destroy",
"sls:package": "AWS_PROFILE=default sls package",
"sls:deploy": "AWS_PROFILE=default sls deploy",
"sls:remove": "AWS_PROFILE=default sls remove"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"aws-sdk": "^2.1692.0"
"@aws-sdk/client-dynamodb": "^3.699.0",
"@aws-sdk/lib-dynamodb": "^3.699.0",
"@types/uuid": "^10.0.0",
"aws-sdk": "^2.1692.0",
"uuid": "^11.0.3"
},
"devDependencies": {
"@types/node": "^22.9.1",
"eslint": "^9.15.0",
"prettier": "^3.3.3",
"serverless-prune-plugin": "^2.1.0",
"typescript": "^5.6.3"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,179 @@
service: tasker-server
plugins:
- serverless-prune-plugin
provider:
stackName: ${self:service}
name: aws
region: "eu-north-1"
runtime: nodejs20.x
environment:
SLS_REGION: ${self:provider.region}
API_BASE_URL: ${ssm:/tasker/api/base-url}
TASKER_TASK_TABLE_NAME: ${ssm:/tasker/dynamodb/task-table-name}
TASKER_PROJECT_TABLE_NAME: ${ssm:/tasker/dynamodb/project-table-name}
TASKER_USER_TABLE_NAME: ${ssm:/tasker/dynamodb/user-table-name}
TASKER_TASK_EXTRA_TABLE_NAME: ${ssm:/tasker/dynamodb/task-extra-table-name}
TASKER_TEAM_TABLE_NAME: ${ssm:/tasker/dynamodb/team-table-name}
layers:
- ${ssm:/tasker/layers/tasker-layer-arn}
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
Resource:
[
"arn:aws:dynamodb:${self:provider.region}:*:table/tasker-*",
"arn:aws:dynamodb:${self:provider.region}:*:table/tasker-*/*",
]
- Effect: Allow
Action:
- execute-api:Invoke
Resource:
- "arn:aws:execute-api:${self:provider.region}:*:*/*/POST/users"
functions:
populateSeedData:
handler: seed/populateSeedData.handler
memorySize: 1024
timeout: 60
# POST /users or triggered by Cognito
createUser:
handler: src/handlers/createUser.handler
memorySize: 1024
timeout: 60
events:
- http:
path: users
method: post
cors: true
authorizer: aws_iam
- cognitoUserPool:
existing: true
pool: ${ssm:/tasker/cognito/user-pool-name}
trigger: PostConfirmation
# POST /projects
createProject:
handler: src/handlers/createProject.handler
memorySize: 1024
timeout: 60
events:
- http:
path: projects
method: post
cors: true
authorizer:
type: COGNITO_USER_POOLS
arn: ${ssm:/tasker/cognito/user-pool-arn}
# POST /tasks
createTask:
handler: src/handlers/createTask.handler
memorySize: 1024
timeout: 60
events:
- http:
path: tasks
method: post
cors: true
authorizer:
type: COGNITO_USER_POOLS
arn: ${ssm:/tasker/cognito/user-pool-arn}
# GET /projects
getProjects:
handler: src/handlers/getProjects.handler
memorySize: 1024
timeout: 60
events:
- http:
path: projects
method: get
cors: true
authorizer:
type: COGNITO_USER_POOLS
arn: ${ssm:/tasker/cognito/user-pool-arn}
# GET /tasks?projectId=
getTasks:
handler: src/handlers/getTasks.handler
memorySize: 1024
timeout: 60
events:
- http:
path: tasks
method: get
cors: true
authorizer:
type: COGNITO_USER_POOLS
arn: ${ssm:/tasker/cognito/user-pool-arn}
# GET /teams
getTeams:
handler: src/handlers/getTeams.handler
memorySize: 1024
timeout: 60
events:
- http:
path: teams
method: get
cors: true
authorizer:
type: COGNITO_USER_POOLS
arn: ${ssm:/tasker/cognito/user-pool-arn}
# GET /users
getUsers:
handler: src/handlers/getUsers.handler
memorySize: 1024
timeout: 60
events:
- http:
path: users
method: get
cors: true
authorizer:
type: COGNITO_USER_POOLS
arn: ${ssm:/tasker/cognito/user-pool-arn}
# GET /users/{cognitoId}
getUser:
handler: src/handlers/getUser.handler
memorySize: 1024
timeout: 60
events:
- http:
path: users/{cognitoId}
method: get
cors: true
authorizer:
type: COGNITO_USER_POOLS
arn: ${ssm:/tasker/cognito/user-pool-arn}
# GET /tasks/user/${userId}
getUserTasks:
handler: src/handlers/getUserTasks.handler
memorySize: 1024
timeout: 60
events:
- http:
path: tasks/user/{userId}
method: get
cors: true
authorizer:
type: COGNITO_USER_POOLS
arn: ${ssm:/tasker/cognito/user-pool-arn}
# PATCH /tasks/{taskId}/status
updateTaskStatus:
handler: src/handlers/updateTaskStatus.handler
memorySize: 1024
timeout: 60
events:
- http:
path: tasks/{taskId}/status
method: patch
cors: true
authorizer:
type: COGNITO_USER_POOLS
arn: ${ssm:/tasker/cognito/user-pool-arn}

View File

@@ -0,0 +1,51 @@
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument, PutCommandInput } from "@aws-sdk/lib-dynamodb";
import { v4 as uuidv4 } from "uuid";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_PROJECT_TABLE_NAME = process.env.TASKER_PROJECT_TABLE_NAME || "";
const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => {
const { name, description, startDate, endDate } = JSON.parse(event.body);
try {
const newProject = {
category: "projects",
projectId: `project_${uuidv4()}`,
name,
description,
startDate,
endDate,
};
const params: PutCommandInput = {
TableName: TASKER_PROJECT_TABLE_NAME,
Item: newProject,
};
await docClient.put(params);
return {
statusCode: 201,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(newProject),
};
} catch (error: any) {
return {
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error creating project: ${error.message}`,
}),
};
}
};

View File

@@ -0,0 +1,69 @@
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument, PutCommandInput } from "@aws-sdk/lib-dynamodb";
import { v4 as uuidv4 } from "uuid";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_TASK_TABLE_NAME = process.env.TASKER_TASK_TABLE_NAME || "";
const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => {
const {
title,
description,
status,
priority,
tags,
startDate,
dueDate,
points,
projectId,
authorUserId,
assignedUserId,
} = JSON.parse(event.body);
try {
const newTask = {
category: "tasks",
taskId: `task_${uuidv4()}`,
title,
description,
status,
priority,
tags,
startDate,
dueDate,
points,
projectId,
authorUserId,
assignedUserId,
};
const params: PutCommandInput = {
TableName: TASKER_TASK_TABLE_NAME,
Item: newTask,
};
await docClient.put(params);
return {
statusCode: 201,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(newTask),
};
} catch (error: any) {
return {
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error creating task: ${error.message}`,
}),
};
}
};

View File

@@ -0,0 +1,42 @@
import { fetchRandomTeamId } from "@/lib/util";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument, PutCommandInput } from "@aws-sdk/lib-dynamodb";
import { v4 as uuidv4 } from "uuid";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_USER_TABLE_NAME = process.env.TASKER_USER_TABLE_NAME || "";
const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => {
console.info(`Event: ${JSON.stringify(event)}`);
const username =
event.request.userAttributes["preferred_username"] || event.userName;
const cognitoId = event.userName;
const teamId = await fetchRandomTeamId();
try {
const newUser = {
category: "users",
cognitoId,
userId: `user_${uuidv4()}`,
username,
profilePictureUrl: "p0.jpeg",
teamId,
};
const params: PutCommandInput = {
TableName: TASKER_USER_TABLE_NAME,
Item: newUser,
};
await docClient.put(params);
console.info(`User ${username} created with teamId ${teamId}`);
} catch (error: any) {
throw new Error(`Error creating user: ${error.message}`);
}
return event;
};

View File

@@ -0,0 +1,42 @@
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_PROJECT_TABLE_NAME = process.env.TASKER_PROJECT_TABLE_NAME || "";
const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => {
try {
const params: QueryCommandInput = {
TableName: TASKER_PROJECT_TABLE_NAME,
KeyConditionExpression: "category = :category",
ExpressionAttributeValues: {
":category": "projects",
},
};
const projects = await docClient.query(params);
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(projects.Items),
};
} catch (error: any) {
return {
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving projects: ${error.message}`,
}),
};
}
};

View File

@@ -0,0 +1,75 @@
import {
fetchAttachments,
fetchComments,
fetchUserWithUserId,
} from "@/lib/util";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_TASK_TABLE_NAME = process.env.TASKER_TASK_TABLE_NAME || "";
const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => {
const { projectId } = event.queryStringParameters;
try {
const params: QueryCommandInput = {
TableName: TASKER_TASK_TABLE_NAME,
KeyConditionExpression: "category = :category AND projectId = :projectId",
IndexName: "GSI-project-id",
ExpressionAttributeValues: {
":category": "tasks",
":projectId": projectId,
},
};
const result = await docClient.query(params);
const tasks = result.Items || [];
const tasksWithDetails = await Promise.all(
tasks.map(async (task: any) => {
const author = task.authorUserId
? await fetchUserWithUserId(task.authorUserId)
: null;
const assignee = task.assignedUserId
? await fetchUserWithUserId(task.assignedUserId)
: null;
const comments = await fetchComments(task.taskId);
const attachments = await fetchAttachments(task.taskId);
return {
...task,
author,
assignee,
comments,
attachments,
};
})
);
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(tasksWithDetails),
};
} catch (error: any) {
return {
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving tasks: ${error.message}`,
}),
};
}
};

View File

@@ -0,0 +1,62 @@
import { fetchUserWithUserId } from "@/lib/util";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_TEAM_TABLE_NAME = process.env.TASKER_TEAM_TABLE_NAME || "";
const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => {
try {
const params: QueryCommandInput = {
TableName: TASKER_TEAM_TABLE_NAME,
KeyConditionExpression: "category = :category",
ExpressionAttributeValues: {
":category": "teams",
},
};
const result = await docClient.query(params);
const teams = result.Items || [];
const teamsWithUsernames = await Promise.all(
teams.map(async (team: any) => {
const productOwnerUsername = team.productOwnerUserId
? (await fetchUserWithUserId(team.productOwnerUserId))?.username
: null;
const projectManagerUsername = team.projectManagerUserId
? (await fetchUserWithUserId(team.projectManagerUserId))?.username
: null;
return {
...team,
productOwnerUsername,
projectManagerUsername,
};
})
);
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(teamsWithUsernames),
};
} catch (error: any) {
return {
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving teams: ${error.message}`,
}),
};
}
};

View File

@@ -0,0 +1,44 @@
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_USER_TABLE_NAME = process.env.TASKER_USER_TABLE_NAME || "";
const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => {
const { cognitoId } = event.pathParameters;
try {
const params: QueryCommandInput = {
TableName: TASKER_USER_TABLE_NAME,
KeyConditionExpression: "category = :category AND cognitoId = :cognitoId",
ExpressionAttributeValues: {
":category": "users",
":cognitoId": cognitoId,
},
};
const user = await docClient.query(params);
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(user.Items?.[0] || {}),
};
} catch (error: any) {
return {
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving user: ${error.message}`,
}),
};
}
};

View File

@@ -0,0 +1,40 @@
import { queryTasks } from "@/lib/util";
export const handler = async (event: any): Promise<any> => {
const { userId } = event.pathParameters;
try {
const authorTasks = await queryTasks(
userId,
"GSI-author-user-id",
"authorUserId"
);
const assigneeTasks = await queryTasks(
userId,
"GSI-assigned-user-id",
"assignedUserId"
);
const userTasks = [...authorTasks, ...assigneeTasks];
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(userTasks),
};
} catch (error: any) {
return {
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving tasks for user: ${error.message}`,
}),
};
}
};

View File

@@ -0,0 +1,42 @@
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_USER_TABLE_NAME = process.env.TASKER_USER_TABLE_NAME || "";
const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => {
try {
const params: QueryCommandInput = {
TableName: TASKER_USER_TABLE_NAME,
KeyConditionExpression: "category = :category",
ExpressionAttributeValues: {
":category": "users",
},
};
const users = await docClient.query(params);
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(users.Items),
};
} catch (error: any) {
return {
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving users: ${error.message}`,
}),
};
}
};

View File

@@ -0,0 +1,52 @@
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument, UpdateCommandInput } from "@aws-sdk/lib-dynamodb";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_TASK_TABLE_NAME = process.env.TASKER_TASK_TABLE_NAME || "";
const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => {
const { taskId } = event.pathParameters;
const { status } = JSON.parse(event.body);
try {
const params: UpdateCommandInput = {
TableName: TASKER_TASK_TABLE_NAME,
Key: {
category: "tasks",
taskId,
},
UpdateExpression: "set #status = :status",
ExpressionAttributeNames: {
"#status": "status",
},
ExpressionAttributeValues: {
":status": status,
},
ReturnValues: "ALL_NEW",
};
const updatedTask = await docClient.update(params);
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(updatedTask.Attributes),
};
} catch (error: any) {
return {
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error updating task: ${error.message}`,
}),
};
}
};

View File

@@ -0,0 +1,97 @@
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_TEAM_TABLE_NAME = process.env.TASKER_TEAM_TABLE_NAME || "";
const TASKER_USER_TABLE_NAME = process.env.TASKER_USER_TABLE_NAME || "";
const TASKER_TASK_TABLE_NAME = process.env.TASKER_TASK_TABLE_NAME || "";
const TASKER_TASK_EXTRA_TABLE_NAME =
process.env.TASKER_TASK_EXTRA_TABLE_NAME || "";
const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const fetchRandomTeamId = async () => {
const params = {
TableName: TASKER_TEAM_TABLE_NAME,
KeyConditionExpression: "category = :category",
ExpressionAttributeValues: {
":category": "teams",
},
};
const teams = await docClient.query(params);
if (!teams.Items) {
return null;
}
const randomTeam =
teams.Items[Math.floor(Math.random() * teams.Items.length)];
return randomTeam.teamId;
};
export const fetchUserWithUserId = async (userId: string): Promise<any> => {
const params: QueryCommandInput = {
TableName: TASKER_USER_TABLE_NAME,
KeyConditionExpression: "category = :category AND userId = :userId",
IndexName: "GSI-user-id",
ExpressionAttributeValues: {
":category": "users",
":userId": userId,
},
};
const result = await docClient.query(params);
return result.Items?.[0];
};
export const fetchComments = async (taskId: string): Promise<any> => {
const params: QueryCommandInput = {
TableName: TASKER_TASK_EXTRA_TABLE_NAME,
KeyConditionExpression: "category = :category AND taskId = :taskId",
IndexName: "GSI-task-id",
ExpressionAttributeValues: {
":category": "comments",
":taskId": taskId,
},
};
const result = await docClient.query(params);
return result.Items;
};
export const fetchAttachments = async (taskId: string): Promise<any> => {
const params: QueryCommandInput = {
TableName: TASKER_TASK_EXTRA_TABLE_NAME,
KeyConditionExpression: "category = :category AND taskId = :taskId",
IndexName: "GSI-task-id",
ExpressionAttributeValues: {
":category": "attachments",
":taskId": taskId,
},
};
const result = await docClient.query(params);
return result.Items;
};
export const queryTasks = async (
userId: string,
indexName: string,
key: string
): Promise<any> => {
const params: QueryCommandInput = {
TableName: TASKER_TASK_TABLE_NAME,
KeyConditionExpression: "category = :category AND #key = :userId",
IndexName: indexName,
ExpressionAttributeValues: {
":category": "tasks",
":userId": userId,
},
ExpressionAttributeNames: {
"#key": key,
},
};
const result = await docClient.query(params);
return result.Items ?? [];
};

View File

@@ -76,6 +76,20 @@ resource "aws_ssm_parameter" "user_pool_id" {
value = aws_cognito_user_pool.tasker_cognito_user_pool.id
}
resource "aws_ssm_parameter" "user_pool_arn" {
name = "/tasker/cognito/user-pool-arn"
description = "Tasker Cognito User Pool ARN"
type = "String"
value = aws_cognito_user_pool.tasker_cognito_user_pool.arn
}
resource "aws_ssm_parameter" "user_pool_name" {
name = "/tasker/cognito/user-pool-name"
description = "Tasker Cognito User Pool Name"
type = "String"
value = aws_cognito_user_pool.tasker_cognito_user_pool.name
}
resource "aws_ssm_parameter" "client_id" {
name = "/tasker/cognito/client-id"
description = "Tasker Cognito Client ID"

View File

@@ -1,11 +1,11 @@
resource "aws_dynamodb_table" "tasker_project_table" {
name = "tasker-project-table"
billing_mode = "PAY_PER_REQUEST"
hash_key = "type"
hash_key = "category"
range_key = "projectId"
attribute {
name = "type"
name = "category"
type = "S"
}
@@ -30,11 +30,11 @@ resource "aws_ssm_parameter" "tasker_project_table_arn" {
resource "aws_dynamodb_table" "tasker_user_table" {
name = "tasker-user-table"
billing_mode = "PAY_PER_REQUEST"
hash_key = "type"
hash_key = "category"
range_key = "cognitoId"
attribute {
name = "type"
name = "category"
type = "S"
}
@@ -50,7 +50,7 @@ resource "aws_dynamodb_table" "tasker_user_table" {
global_secondary_index {
name = "GSI-user-id"
hash_key = "type"
hash_key = "category"
range_key = "userId"
projection_type = "ALL"
}
@@ -71,11 +71,11 @@ resource "aws_ssm_parameter" "tasker_user_table_arn" {
resource "aws_dynamodb_table" "tasker_team_table" {
name = "tasker-team-table"
billing_mode = "PAY_PER_REQUEST"
hash_key = "type"
hash_key = "category"
range_key = "teamId"
attribute {
name = "type"
name = "category"
type = "S"
}
@@ -100,11 +100,11 @@ resource "aws_ssm_parameter" "tasker_team_table_arn" {
resource "aws_dynamodb_table" "tasker_task_table" {
name = "tasker-task-table"
billing_mode = "PAY_PER_REQUEST"
hash_key = "type"
hash_key = "category"
range_key = "taskId"
attribute {
name = "type"
name = "category"
type = "S"
}
@@ -130,21 +130,21 @@ resource "aws_dynamodb_table" "tasker_task_table" {
global_secondary_index {
name = "GSI-project-id"
hash_key = "type"
hash_key = "category"
range_key = "projectId"
projection_type = "ALL"
}
global_secondary_index {
name = "GSI-author-user-id"
hash_key = "type"
hash_key = "category"
range_key = "authorUserId"
projection_type = "ALL"
}
global_secondary_index {
name = "GSI-assigned-user-id"
hash_key = "type"
hash_key = "category"
range_key = "assignedUserId"
projection_type = "ALL"
}
@@ -165,11 +165,11 @@ resource "aws_ssm_parameter" "tasker_task_table_arn" {
resource "aws_dynamodb_table" "tasker_task_extra_table" {
name = "tasker-task-extra-table"
billing_mode = "PAY_PER_REQUEST"
hash_key = "type"
hash_key = "category"
range_key = "id"
attribute {
name = "type"
name = "category"
type = "S"
}
@@ -185,7 +185,7 @@ resource "aws_dynamodb_table" "tasker_task_extra_table" {
global_secondary_index {
name = "GSI-task-id"
hash_key = "type"
hash_key = "category"
range_key = "taskId"
projection_type = "ALL"
}

View File

@@ -0,0 +1,24 @@
resource "aws_s3_bucket" "tasker_lambda_layer" {
bucket = "tasker-lambda-layer"
}
resource "aws_s3_object" "tasker_lambda_layer_zip" {
bucket = aws_s3_bucket.tasker_lambda_layer.id
key = "layers/tasker-layer.zip"
source = "../layers/tasker-layer.zip"
}
resource "aws_lambda_layer_version" "tasker_layer" {
layer_name = "tasker-layer"
s3_bucket = aws_s3_object.tasker_lambda_layer_zip.bucket
s3_key = aws_s3_object.tasker_lambda_layer_zip.key
compatible_runtimes = ["nodejs20.x"]
description = "Tasker Lambda Layer with shared dependencies"
}
resource "aws_ssm_parameter" "tasker_layer_arn" {
name = "/tasker/layers/tasker-layer-arn"
type = "String"
value = aws_lambda_layer_version.tasker_layer.arn
}

View File

@@ -1,11 +1,22 @@
resource "aws_s3_bucket" "tasker_public_images" {
bucket = "tasker-public-images"
tags = {
Environment = "Dev"
}
}
resource "aws_s3_bucket_policy" "public_read_policy" {
bucket = aws_s3_bucket.tasker_public_images.id
policy = data.aws_iam_policy_document.public_read_policy.json
}
data "aws_iam_policy_document" "public_read_policy" {
statement {
actions = ["s3:GetObject"]
resources = ["${aws_s3_bucket.tasker_public_images.arn}/*"]
principals {
type = "AWS"
identifiers = ["*"]
}
}
}
resource "aws_s3_bucket_ownership_controls" "tasker_public_images_ownership_controls" {
bucket = aws_s3_bucket.tasker_public_images.id