Skip to content

Commit 76d727c

Browse files
author
Endre Vegh
committed
move lambdas to services
1 parent 75a1081 commit 76d727c

File tree

14 files changed

+379
-60
lines changed

14 files changed

+379
-60
lines changed

packages/api/src/functions/.keep

Whitespace-only changes.

packages/api/src/functions/cookie_manager.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/api/src/functions/graphql.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/api/src/functions/image_upload.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/api/src/functions/refresh_token.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/api/src/functions/send_email_verification.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import middy from "@middy/core";
2+
import cors from "@middy/http-cors";
3+
import httpErrorHandler from "@middy/http-error-handler";
4+
import { cookieManager, jwtMiddleware } from "@saruni/auth";
5+
6+
export const handler = middy(cookieManager())
7+
.use(jwtMiddleware())
8+
.use(httpErrorHandler())
9+
.use(
10+
cors({
11+
credentials: true,
12+
headers:
13+
"Content-Type, X-Amz-Date, Authorization, X-Api-Key, X-Amz-Security-Token, X-Amz-User-Agent",
14+
origin: "http://localhost:3000",
15+
})
16+
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import middy from "@middy/core";
2+
import cors from "@middy/http-cors";
3+
import httpErrorHandler from "@middy/http-error-handler";
4+
import { refreshToken } from "@saruni/auth";
5+
6+
export const handler = middy(refreshToken())
7+
.use(httpErrorHandler())
8+
.use(
9+
cors({
10+
credentials: true,
11+
headers:
12+
"Content-Type, X-Amz-Date, Cookie, Authorization, X-Api-Key, X-Amz-Security-Token, X-Amz-User-Agent",
13+
origin: "http://localhost:3000",
14+
})
15+
);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Type: AWS::IAM::Role
2+
Properties:
3+
AssumeRolePolicyDocument:
4+
Statement:
5+
- Effect: Allow
6+
Action: sts:AssumeRole
7+
Principal:
8+
Service: lambda.amazonaws.com
9+
Version: "2012-10-17"
10+
Policies:
11+
- PolicyName: log
12+
PolicyDocument:
13+
Version: "2012-10-17"
14+
Statement:
15+
- Effect: Allow
16+
Action:
17+
- logs:CreateLogStream
18+
- logs:CreateLogGroup
19+
- logs:PutLogEvents
20+
Resource: arn:aws:logs:*:*:*
21+
- PolicyName: ssm
22+
PolicyDocument:
23+
Version: "2012-10-17"
24+
Statement:
25+
- Effect: Allow
26+
Action:
27+
- ssm:GetParameter
28+
Resource:
29+
Fn::Join:
30+
- ""
31+
- - "arn:aws:ssm:"
32+
- Ref: AWS::Region
33+
- ":"
34+
- Ref: AWS::AccountId
35+
- ":parameter/pooopoo/*"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
service: auth-${self:custom.stage}
2+
3+
provider:
4+
name: aws
5+
region: eu-west-1
6+
stage: dev
7+
runtime: nodejs12.x
8+
apiGateway:
9+
restApiId:
10+
"Fn::ImportValue": ${self:custom.stage}-ExtApiGatewayRestApiId
11+
restApiRootResourceId:
12+
"Fn::ImportValue": ${self:custom.stage}-ExtApiGatewayRestApiRootResourceId
13+
14+
custom:
15+
restApiId:
16+
"Fn::ImportValue": ${self:custom.stage}-ExtApiGatewayRestApiId
17+
domain:
18+
{
19+
"Fn::Join":
20+
[
21+
"",
22+
[
23+
"${self:custom.restApiId}",
24+
".execute-api.",
25+
"${self:provider.region}",
26+
".amazonaws.com",
27+
],
28+
],
29+
}
30+
stage: ${opt:stage, self:provider.stage}
31+
webpack:
32+
keepOutputDirectory: true
33+
webpackConfig: "../../../webpack.config.js"
34+
includeModules:
35+
packagePath: "../../../package.json"
36+
forceExclude:
37+
- "aws-sdk"
38+
packager: "yarn"
39+
40+
plugins:
41+
- serverless-pseudo-parameters
42+
- serverless-webpack
43+
44+
package:
45+
individually: true
46+
47+
resources:
48+
Resources:
49+
AuthLambdaRole: ${file(./resources/AuthLambdaRole.yml)}
50+
51+
functions:
52+
cookieManager:
53+
role: AuthLambdaRole
54+
environment:
55+
DOMAIN: ${self:custom.domain}
56+
STAGE: ${self:custom.stage}
57+
ACCESS_TOKEN_SECRET:
58+
"Fn::ImportValue": ${self:custom.stage}-AccessTokenSecret
59+
REFRESH_TOKEN_SECRET:
60+
"Fn::ImportValue": ${self:custom.stage}-RefreshTokenSecret
61+
handler: cookieManager.handler
62+
events:
63+
- http:
64+
path: /cookieManager
65+
method: put
66+
cors:
67+
origin:
68+
- "http://localhost:3000"
69+
headers:
70+
- Content-Type
71+
- X-Amz-Date
72+
- Authorization
73+
- X-Api-Key
74+
- X-Amz-Security-Token
75+
- X-Amz-User-Agent
76+
allowCredentials: true
77+
- http:
78+
path: /cookieManager
79+
method: delete
80+
cors:
81+
origin:
82+
- "http://localhost:3000"
83+
headers:
84+
- Content-Type
85+
- X-Amz-Date
86+
- Authorization
87+
- X-Api-Key
88+
- X-Amz-Security-Token
89+
- X-Amz-User-Agent
90+
allowCredentials: true
91+
refreshToken:
92+
role: AuthLambdaRole
93+
environment:
94+
DOMAIN: ${self:custom.domain}
95+
STAGE: ${self:custom.stage}
96+
ACCESS_TOKEN_SECRET:
97+
"Fn::ImportValue": ${self:custom.stage}-AccessTokenSecret
98+
REFRESH_TOKEN_SECRET:
99+
"Fn::ImportValue": ${self:custom.stage}-RefreshTokenSecret
100+
handler: refreshToken.handler
101+
events:
102+
- http:
103+
path: /refreshToken
104+
method: post
105+
cors:
106+
origin:
107+
- "http://localhost:3000"
108+
headers:
109+
- Content-Type
110+
- X-Amz-Date
111+
- Authorization
112+
- X-Api-Key
113+
- X-Amz-Security-Token
114+
- X-Amz-User-Agent
115+
allowCredentials: true

0 commit comments

Comments
 (0)