@webiny/pulumi-aws 5.34.8 → 5.35.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -7
- package/apps/admin/createAdminPulumiApp.js +0 -5
- package/apps/admin/createAdminPulumiApp.js.map +1 -1
- package/apps/admin/index.js +0 -2
- package/apps/admin/index.js.map +1 -1
- package/apps/api/ApiApwScheduler.js +9 -21
- package/apps/api/ApiApwScheduler.js.map +1 -1
- package/apps/api/ApiCloudfront.js +0 -7
- package/apps/api/ApiCloudfront.js.map +1 -1
- package/apps/api/ApiFileManager.d.ts +5 -1
- package/apps/api/ApiFileManager.js +8 -17
- package/apps/api/ApiFileManager.js.map +1 -1
- package/apps/api/ApiGateway.js +0 -10
- package/apps/api/ApiGateway.js.map +1 -1
- package/apps/api/ApiGraphql.js +4 -25
- package/apps/api/ApiGraphql.js.map +1 -1
- package/apps/api/ApiMigration.d.ts +5 -0
- package/apps/api/ApiMigration.js +58 -0
- package/apps/api/ApiMigration.js.map +1 -0
- package/apps/api/ApiOutput.js +0 -7
- package/apps/api/ApiOutput.js.map +1 -1
- package/apps/api/ApiPageBuilder.js +11 -24
- package/apps/api/ApiPageBuilder.js.map +1 -1
- package/apps/api/createApiPulumiApp.d.ts +3 -12
- package/apps/api/createApiPulumiApp.js +28 -46
- package/apps/api/createApiPulumiApp.js.map +1 -1
- package/apps/api/index.d.ts +1 -1
- package/apps/api/index.js +4 -22
- package/apps/api/index.js.map +1 -1
- package/apps/awsUtils.d.ts +1 -1
- package/apps/awsUtils.js +0 -4
- package/apps/awsUtils.js.map +1 -1
- package/apps/common/CoreOutput.js +0 -7
- package/apps/common/CoreOutput.js.map +1 -1
- package/apps/common/VpcConfig.js +0 -7
- package/apps/common/VpcConfig.js.map +1 -1
- package/apps/common/index.js +0 -4
- package/apps/common/index.js.map +1 -1
- package/apps/core/CoreCognito.js +12 -9
- package/apps/core/CoreCognito.js.map +1 -1
- package/apps/core/CoreDynamo.js +0 -6
- package/apps/core/CoreDynamo.js.map +1 -1
- package/apps/core/CoreElasticSearch.js +9 -24
- package/apps/core/CoreElasticSearch.js.map +1 -1
- package/apps/core/CoreEventBus.js +0 -6
- package/apps/core/CoreEventBus.js.map +1 -1
- package/apps/core/CoreFileManager.js +2 -7
- package/apps/core/CoreFileManager.js.map +1 -1
- package/apps/core/CoreVpc.js +10 -11
- package/apps/core/CoreVpc.js.map +1 -1
- package/apps/core/createCorePulumiApp.js +13 -21
- package/apps/core/createCorePulumiApp.js.map +1 -1
- package/apps/core/index.js +0 -12
- package/apps/core/index.js.map +1 -1
- package/apps/createAppBucket.js +11 -10
- package/apps/createAppBucket.js.map +1 -1
- package/apps/customDomain.js +0 -1
- package/apps/customDomain.js.map +1 -1
- package/apps/index.js +0 -13
- package/apps/index.js.map +1 -1
- package/apps/lambdaUtils.js +2 -10
- package/apps/lambdaUtils.js.map +1 -1
- package/apps/react/createReactPulumiApp.js +6 -21
- package/apps/react/createReactPulumiApp.js.map +1 -1
- package/apps/react/index.js +0 -2
- package/apps/react/index.js.map +1 -1
- package/apps/tenantRouter.js +6 -14
- package/apps/tenantRouter.js.map +1 -1
- package/apps/website/WebsitePrerendering.js +6 -20
- package/apps/website/WebsitePrerendering.js.map +1 -1
- package/apps/website/createWebsitePulumiApp.js +8 -28
- package/apps/website/createWebsitePulumiApp.js.map +1 -1
- package/apps/website/deliveryViewerRequest.js +10 -9
- package/apps/website/deliveryViewerRequest.js.map +1 -1
- package/apps/website/index.js +0 -2
- package/apps/website/index.js.map +1 -1
- package/components/tenantRouter/WebsiteTenantRouter.js +2 -12
- package/components/tenantRouter/WebsiteTenantRouter.js.map +1 -1
- package/components/tenantRouter/functions/origin/request.js +19 -27
- package/components/tenantRouter/functions/origin/request.js.map +1 -1
- package/enterprise/createAdminPulumiApp.js +0 -1
- package/enterprise/createAdminPulumiApp.js.map +1 -1
- package/enterprise/createApiPulumiApp.d.ts +3 -7
- package/enterprise/createApiPulumiApp.js +4 -17
- package/enterprise/createApiPulumiApp.js.map +1 -1
- package/enterprise/createCorePulumiApp.js +21 -34
- package/enterprise/createCorePulumiApp.js.map +1 -1
- package/enterprise/createWebsitePulumiApp.js +2 -17
- package/enterprise/createWebsitePulumiApp.js.map +1 -1
- package/enterprise/index.js +0 -8
- package/enterprise/index.js.map +1 -1
- package/index.js +0 -5
- package/index.js.map +1 -1
- package/package.json +9 -9
- package/utils/addDomainsUrlsOutputs.js +6 -10
- package/utils/addDomainsUrlsOutputs.js.map +1 -1
- package/utils/crawlDirectory.js +0 -8
- package/utils/crawlDirectory.js.map +1 -1
- package/utils/getPresignedPost.js +0 -7
- package/utils/getPresignedPost.js.map +1 -1
- package/utils/index.js +0 -7
- package/utils/index.js.map +1 -1
- package/utils/lambdaEnvVariables.js +5 -15
- package/utils/lambdaEnvVariables.js.map +1 -1
- package/utils/storageMigrate.js.map +1 -1
- package/utils/tagResources.js +3 -10
- package/utils/tagResources.js.map +1 -1
- package/utils/uploadFolderToS3.js +2 -36
- package/utils/uploadFolderToS3.js.map +1 -1
package/README.md
CHANGED
|
@@ -161,13 +161,6 @@ export declare const createApiPulumiApp: (projectAppParams?: CreateApiAppParams)
|
|
|
161
161
|
graphql: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/lambda").Function>;
|
|
162
162
|
};
|
|
163
163
|
};
|
|
164
|
-
headlessCms: {
|
|
165
|
-
role: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/iam").Role>;
|
|
166
|
-
policy: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/iam").Policy>;
|
|
167
|
-
functions: {
|
|
168
|
-
graphql: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/lambda").Function>;
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
164
|
apiGateway: {
|
|
172
165
|
api: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/apigatewayv2").Api>;
|
|
173
166
|
stage: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/apigatewayv2").Stage>;
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createAdminPulumiApp = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _ = require("./..");
|
|
13
|
-
|
|
14
10
|
const createAdminPulumiApp = projectAppParams => {
|
|
15
11
|
return (0, _.createReactPulumiApp)((0, _objectSpread2.default)({
|
|
16
12
|
name: "admin",
|
|
17
13
|
folder: "apps/admin"
|
|
18
14
|
}, projectAppParams));
|
|
19
15
|
};
|
|
20
|
-
|
|
21
16
|
exports.createAdminPulumiApp = createAdminPulumiApp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createAdminPulumiApp","projectAppParams","createReactPulumiApp","name","folder"],"sources":["createAdminPulumiApp.ts"],"sourcesContent":["import { PulumiAppParam, PulumiAppParamCallback } from \"@webiny/pulumi\";\nimport { createReactPulumiApp, CustomDomainParams } from \"~/apps\";\n\nexport type AdminPulumiApp = ReturnType<typeof createReactPulumiApp>;\n\nexport interface CreateAdminPulumiAppParams {\n /** Custom domain configuration */\n domains?: PulumiAppParamCallback<CustomDomainParams>;\n\n /**\n * Provides a way to adjust existing Pulumi code (cloud infrastructure resources)\n * or add additional ones into the mix.\n */\n pulumi?: (app: AdminPulumiApp) => void | Promise<void>;\n\n /**\n * Prefixes names of all Pulumi cloud infrastructure resource with given prefix.\n */\n pulumiResourceNamePrefix?: PulumiAppParam<string>;\n\n /**\n * Treats provided environments as production environments, which\n * are deployed in production deployment mode.\n * https://www.webiny.com/docs/architecture/deployment-modes/production\n */\n productionEnvironments?: PulumiAppParam<string[]>;\n}\n\nexport const createAdminPulumiApp = (projectAppParams: CreateAdminPulumiAppParams) => {\n return createReactPulumiApp({\n name: \"admin\",\n folder: \"apps/admin\",\n ...projectAppParams\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["createAdminPulumiApp","projectAppParams","createReactPulumiApp","name","folder"],"sources":["createAdminPulumiApp.ts"],"sourcesContent":["import { PulumiAppParam, PulumiAppParamCallback } from \"@webiny/pulumi\";\nimport { createReactPulumiApp, CustomDomainParams } from \"~/apps\";\n\nexport type AdminPulumiApp = ReturnType<typeof createReactPulumiApp>;\n\nexport interface CreateAdminPulumiAppParams {\n /** Custom domain configuration */\n domains?: PulumiAppParamCallback<CustomDomainParams>;\n\n /**\n * Provides a way to adjust existing Pulumi code (cloud infrastructure resources)\n * or add additional ones into the mix.\n */\n pulumi?: (app: AdminPulumiApp) => void | Promise<void>;\n\n /**\n * Prefixes names of all Pulumi cloud infrastructure resource with given prefix.\n */\n pulumiResourceNamePrefix?: PulumiAppParam<string>;\n\n /**\n * Treats provided environments as production environments, which\n * are deployed in production deployment mode.\n * https://www.webiny.com/docs/architecture/deployment-modes/production\n */\n productionEnvironments?: PulumiAppParam<string[]>;\n}\n\nexport const createAdminPulumiApp = (projectAppParams: CreateAdminPulumiAppParams) => {\n return createReactPulumiApp({\n name: \"admin\",\n folder: \"apps/admin\",\n ...projectAppParams\n });\n};\n"],"mappings":";;;;;;;;AACA;AA2BO,MAAMA,oBAAoB,GAAIC,gBAA4C,IAAK;EAClF,OAAO,IAAAC,sBAAoB;IACvBC,IAAI,EAAE,OAAO;IACbC,MAAM,EAAE;EAAY,GACjBH,gBAAgB,EACrB;AACN,CAAC;AAAC"}
|
package/apps/admin/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _createAdminPulumiApp = require("./createAdminPulumiApp");
|
|
8
|
-
|
|
9
7
|
Object.keys(_createAdminPulumiApp).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _createAdminPulumiApp[key]) return;
|
package/apps/admin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./createAdminPulumiApp\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./createAdminPulumiApp\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.ApiApwScheduler = void 0;
|
|
11
|
-
|
|
12
9
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
|
-
|
|
14
10
|
var _path = _interopRequireDefault(require("path"));
|
|
15
|
-
|
|
16
11
|
var pulumi = _interopRequireWildcard(require("@pulumi/pulumi"));
|
|
17
|
-
|
|
18
12
|
var aws = _interopRequireWildcard(require("@pulumi/aws"));
|
|
19
|
-
|
|
20
13
|
var _pulumi2 = require("@webiny/pulumi");
|
|
21
|
-
|
|
22
14
|
var _common = require("../common");
|
|
23
|
-
|
|
24
15
|
var _lambdaUtils = require("../lambdaUtils");
|
|
25
|
-
|
|
26
16
|
const LAMBDA_NAME_PREFIX = "apw-scheduler";
|
|
27
17
|
const CREATE_RULE_LAMBDA = `${LAMBDA_NAME_PREFIX}-schedule-action-lambda`;
|
|
28
18
|
const EXECUTE_ACTION_LAMBDA = `${LAMBDA_NAME_PREFIX}-execute-action-lambda`;
|
|
@@ -30,11 +20,11 @@ const EVENT_RULE_NAME = `${LAMBDA_NAME_PREFIX}-event-rule`;
|
|
|
30
20
|
const EVENT_RULE_TARGET = `${LAMBDA_NAME_PREFIX}-event-rule-target`;
|
|
31
21
|
const ApiApwScheduler = (0, _pulumi2.createAppModule)({
|
|
32
22
|
name: "ApiApwScheduler",
|
|
33
|
-
|
|
34
23
|
config(app, params) {
|
|
35
24
|
const executeAction = createExecuteActionLambda(app, params);
|
|
36
|
-
const scheduleAction = createScheduleActionLambda(app, executeAction.lambda.output, params);
|
|
25
|
+
const scheduleAction = createScheduleActionLambda(app, executeAction.lambda.output, params);
|
|
37
26
|
|
|
27
|
+
// Create event rule.
|
|
38
28
|
const eventRule = app.addResource(aws.cloudwatch.EventRule, {
|
|
39
29
|
name: EVENT_RULE_NAME,
|
|
40
30
|
config: {
|
|
@@ -42,8 +32,9 @@ const ApiApwScheduler = (0, _pulumi2.createAppModule)({
|
|
|
42
32
|
scheduleExpression: "cron(* * * * ? 2000)",
|
|
43
33
|
isEnabled: true
|
|
44
34
|
}
|
|
45
|
-
});
|
|
35
|
+
});
|
|
46
36
|
|
|
37
|
+
// Add required permission to the target lambda.
|
|
47
38
|
app.addResource(aws.lambda.Permission, {
|
|
48
39
|
name: "eventTargetPermission",
|
|
49
40
|
config: {
|
|
@@ -52,8 +43,9 @@ const ApiApwScheduler = (0, _pulumi2.createAppModule)({
|
|
|
52
43
|
principal: "events.amazonaws.com",
|
|
53
44
|
statementId: "allow-rule-invoke-" + EVENT_RULE_NAME
|
|
54
45
|
}
|
|
55
|
-
});
|
|
46
|
+
});
|
|
56
47
|
|
|
48
|
+
// Add lambda as target to the event rule.
|
|
57
49
|
const eventTarget = app.addResource(aws.cloudwatch.EventTarget, {
|
|
58
50
|
name: EVENT_RULE_TARGET,
|
|
59
51
|
config: {
|
|
@@ -68,10 +60,8 @@ const ApiApwScheduler = (0, _pulumi2.createAppModule)({
|
|
|
68
60
|
eventTarget
|
|
69
61
|
};
|
|
70
62
|
}
|
|
71
|
-
|
|
72
63
|
});
|
|
73
64
|
exports.ApiApwScheduler = ApiApwScheduler;
|
|
74
|
-
|
|
75
65
|
function createExecuteActionLambda(app, params) {
|
|
76
66
|
const role = app.addResource(aws.iam.Role, {
|
|
77
67
|
name: `${EXECUTE_ACTION_LAMBDA}-role`,
|
|
@@ -129,7 +119,6 @@ function createExecuteActionLambda(app, params) {
|
|
|
129
119
|
lambda
|
|
130
120
|
};
|
|
131
121
|
}
|
|
132
|
-
|
|
133
122
|
function createExecuteActionLambdaPolicy(app) {
|
|
134
123
|
const core = app.getModule(_common.CoreOutput);
|
|
135
124
|
return app.addResource(aws.iam.Policy, {
|
|
@@ -153,7 +142,6 @@ function createExecuteActionLambdaPolicy(app) {
|
|
|
153
142
|
}
|
|
154
143
|
});
|
|
155
144
|
}
|
|
156
|
-
|
|
157
145
|
function createScheduleActionLambda(app, executeLambda, params) {
|
|
158
146
|
const role = app.addResource(aws.iam.Role, {
|
|
159
147
|
name: `${CREATE_RULE_LAMBDA}-role`,
|
|
@@ -202,20 +190,20 @@ function createScheduleActionLambda(app, executeLambda, params) {
|
|
|
202
190
|
}),
|
|
203
191
|
environment: {
|
|
204
192
|
variables: (0, _lambdaUtils.getCommonLambdaEnvVariables)().apply(value => (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, value), params.env), {}, {
|
|
205
|
-
APW_SCHEDULER_EXECUTE_ACTION_HANDLER: executeLambda.arn
|
|
193
|
+
APW_SCHEDULER_EXECUTE_ACTION_HANDLER: executeLambda.arn
|
|
194
|
+
// RULE_NAME: this.eventRule.name.apply(name => name),
|
|
206
195
|
// RULE_TARGET_ID: this.eventTarget.targetId.apply(id => id)
|
|
207
|
-
|
|
208
196
|
}))
|
|
209
197
|
}
|
|
210
198
|
}
|
|
211
199
|
});
|
|
200
|
+
|
|
212
201
|
return {
|
|
213
202
|
role,
|
|
214
203
|
policy,
|
|
215
204
|
lambda
|
|
216
205
|
};
|
|
217
206
|
}
|
|
218
|
-
|
|
219
207
|
function createScheduleActionLambdaPolicy(app) {
|
|
220
208
|
const core = app.getModule(_common.CoreOutput);
|
|
221
209
|
return app.addResource(aws.iam.Policy, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LAMBDA_NAME_PREFIX","CREATE_RULE_LAMBDA","EXECUTE_ACTION_LAMBDA","EVENT_RULE_NAME","EVENT_RULE_TARGET","ApiApwScheduler","createAppModule","name","config","app","params","executeAction","createExecuteActionLambda","scheduleAction","createScheduleActionLambda","lambda","output","eventRule","addResource","aws","cloudwatch","EventRule","description","scheduleExpression","isEnabled","Permission","action","function","arn","principal","statementId","eventTarget","EventTarget","rule","role","iam","Role","assumeRolePolicy","Version","Statement","Action","Principal","Service","Effect","meta","isLambdaFunctionRole","policy","createExecuteActionLambdaPolicy","RolePolicyAttachment","policyArn","ManagedPolicy","AWSLambdaBasicExecutionRole","Function","runtime","handler","timeout","memorySize","code","pulumi","asset","AssetArchive","FileArchive","path","join","paths","workspace","environment","variables","getCommonLambdaEnvVariables","apply","value","env","core","getModule","CoreOutput","Policy","Sid","Resource","interpolate","primaryDynamodbTableArn","executeLambda","createScheduleActionLambdaPolicy","APW_SCHEDULER_EXECUTE_ACTION_HANDLER"],"sources":["ApiApwScheduler.ts"],"sourcesContent":["import path from \"path\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as aws from \"@pulumi/aws\";\nimport { createAppModule, PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\nimport { CoreOutput } from \"../common\";\nimport { getCommonLambdaEnvVariables } from \"../lambdaUtils\";\n\ninterface ScheduleActionParams {\n env: Record<string, any>;\n}\n\nconst LAMBDA_NAME_PREFIX = \"apw-scheduler\";\nconst CREATE_RULE_LAMBDA = `${LAMBDA_NAME_PREFIX}-schedule-action-lambda`;\nconst EXECUTE_ACTION_LAMBDA = `${LAMBDA_NAME_PREFIX}-execute-action-lambda`;\nconst EVENT_RULE_NAME = `${LAMBDA_NAME_PREFIX}-event-rule`;\nconst EVENT_RULE_TARGET = `${LAMBDA_NAME_PREFIX}-event-rule-target`;\n\nexport type ApiApwScheduler = PulumiAppModule<typeof ApiApwScheduler>;\n\nexport const ApiApwScheduler = createAppModule({\n name: \"ApiApwScheduler\",\n config(app: PulumiApp, params: ScheduleActionParams) {\n const executeAction = createExecuteActionLambda(app, params);\n const scheduleAction = createScheduleActionLambda(app, executeAction.lambda.output, params);\n\n // Create event rule.\n const eventRule = app.addResource(aws.cloudwatch.EventRule, {\n name: EVENT_RULE_NAME,\n config: {\n description: `Enable us to schedule an action in publishing workflow at a particular datetime`,\n scheduleExpression: \"cron(* * * * ? 2000)\",\n isEnabled: true\n }\n });\n\n // Add required permission to the target lambda.\n app.addResource(aws.lambda.Permission, {\n name: \"eventTargetPermission\",\n config: {\n action: \"lambda:InvokeFunction\",\n function: scheduleAction.lambda.output.arn,\n principal: \"events.amazonaws.com\",\n statementId: \"allow-rule-invoke-\" + EVENT_RULE_NAME\n }\n });\n\n // Add lambda as target to the event rule.\n const eventTarget = app.addResource(aws.cloudwatch.EventTarget, {\n name: EVENT_RULE_TARGET,\n config: {\n rule: eventRule.output.name,\n arn: scheduleAction.lambda.output.arn\n }\n });\n\n return {\n executeAction,\n scheduleAction,\n eventRule,\n eventTarget\n };\n }\n});\n\nfunction createExecuteActionLambda(app: PulumiApp, params: ScheduleActionParams) {\n const role = app.addResource(aws.iam.Role, {\n name: `${EXECUTE_ACTION_LAMBDA}-role`,\n config: {\n assumeRolePolicy: {\n Version: \"2012-10-17\",\n Statement: [\n {\n Action: \"sts:AssumeRole\",\n Principal: {\n Service: \"lambda.amazonaws.com\"\n },\n Effect: \"Allow\"\n }\n ]\n }\n },\n meta: { isLambdaFunctionRole: true }\n });\n\n const policy = createExecuteActionLambdaPolicy(app);\n\n app.addResource(aws.iam.RolePolicyAttachment, {\n name: `${EXECUTE_ACTION_LAMBDA}-role-policy-attachment`,\n config: {\n role: role.output,\n policyArn: policy.output.arn\n }\n });\n\n app.addResource(aws.iam.RolePolicyAttachment, {\n name: `${EXECUTE_ACTION_LAMBDA}-AWSLambdaBasicExecutionRole`,\n config: {\n role: role.output,\n policyArn: aws.iam.ManagedPolicy.AWSLambdaBasicExecutionRole\n }\n });\n\n const lambda = app.addResource(aws.lambda.Function, {\n name: EXECUTE_ACTION_LAMBDA,\n config: {\n role: role.output.arn,\n runtime: \"nodejs14.x\",\n handler: \"handler.handler\",\n timeout: 60,\n memorySize: 128,\n description: \"Handle execute action workflow in apw scheduler\",\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"apw/executeAction/build\")\n )\n }),\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n ...params.env\n }))\n }\n }\n });\n\n return {\n role,\n policy,\n lambda\n };\n}\n\nfunction createExecuteActionLambdaPolicy(app: PulumiApp) {\n const core = app.getModule(CoreOutput);\n\n return app.addResource(aws.iam.Policy, {\n name: \"ApwSchedulerExecuteActionLambdaPolicy\",\n config: {\n description: \"This policy enables access to cloudwatch event and lambda invocation\",\n policy: {\n Version: \"2012-10-17\",\n Statement: [\n {\n Sid: \"PermissionLambda\",\n Effect: \"Allow\",\n Action: [\"lambda:InvokeFunction\"],\n Resource: [\"*\"]\n },\n {\n Sid: \"PermissionDynamoDB\",\n Effect: \"Allow\",\n Action: [\"dynamodb:Query\", \"dynamodb:GetItem\", \"dynamodb:DeleteItem\"],\n Resource: [\n pulumi.interpolate`${core.primaryDynamodbTableArn}`,\n pulumi.interpolate`${core.primaryDynamodbTableArn}/*`\n ]\n }\n ]\n }\n }\n });\n}\n\nfunction createScheduleActionLambda(\n app: PulumiApp,\n executeLambda: pulumi.Output<aws.lambda.Function>,\n params: ScheduleActionParams\n) {\n const role = app.addResource(aws.iam.Role, {\n name: `${CREATE_RULE_LAMBDA}-role`,\n config: {\n assumeRolePolicy: {\n Version: \"2012-10-17\",\n Statement: [\n {\n Action: \"sts:AssumeRole\",\n Principal: {\n Service: \"lambda.amazonaws.com\"\n },\n Effect: \"Allow\"\n }\n ]\n }\n },\n meta: { isLambdaFunctionRole: true }\n });\n\n const policy = createScheduleActionLambdaPolicy(app);\n\n app.addResource(aws.iam.RolePolicyAttachment, {\n name: `${CREATE_RULE_LAMBDA}-role-policy-attachment`,\n config: {\n role: role.output,\n policyArn: policy.output.arn\n }\n });\n\n app.addResource(aws.iam.RolePolicyAttachment, {\n name: `${CREATE_RULE_LAMBDA}-AWSLambdaBasicExecutionRole`,\n config: {\n role: role.output,\n policyArn: aws.iam.ManagedPolicy.AWSLambdaBasicExecutionRole\n }\n });\n\n const lambda = app.addResource(aws.lambda.Function, {\n name: CREATE_RULE_LAMBDA,\n config: {\n role: role.output.arn,\n runtime: \"nodejs14.x\",\n handler: \"handler.handler\",\n timeout: 60,\n memorySize: 128,\n description: \"Handle schedule action workflow in apw scheduler\",\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"apw/scheduleAction/build\")\n )\n }),\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n ...params.env,\n APW_SCHEDULER_EXECUTE_ACTION_HANDLER: executeLambda.arn\n // RULE_NAME: this.eventRule.name.apply(name => name),\n // RULE_TARGET_ID: this.eventTarget.targetId.apply(id => id)\n }))\n }\n }\n });\n\n return {\n role,\n policy,\n lambda\n };\n}\n\nfunction createScheduleActionLambdaPolicy(app: PulumiApp) {\n const core = app.getModule(CoreOutput);\n\n return app.addResource(aws.iam.Policy, {\n name: \"ApwSchedulerScheduleActionLambdaPolicy\",\n config: {\n description: \"This policy enables access to cloudwatch event and lambda invocation\",\n policy: {\n Version: \"2012-10-17\",\n Statement: [\n {\n Sid: \"PermissionLambda\",\n Effect: \"Allow\",\n Action: [\"lambda:InvokeFunction\"],\n Resource: [\"*\"]\n },\n {\n Sid: \"PermissionDynamoDB\",\n Effect: \"Allow\",\n Action: [\n \"dynamodb:PutItem\",\n \"dynamodb:Query\",\n \"dynamodb:GetItem\",\n \"dynamodb:UpdateItem\",\n \"dynamodb:DeleteItem\"\n ],\n Resource: [\n pulumi.interpolate`${core.primaryDynamodbTableArn}`,\n pulumi.interpolate`${core.primaryDynamodbTableArn}/*`\n ]\n },\n {\n Sid: \"PermissionEvents\",\n Effect: \"Allow\",\n Action: [\n \"events:DeleteRule\",\n \"events:PutTargets\",\n \"events:PutRule\",\n \"events:ListRules\",\n \"events:RemoveTargets\",\n \"events:ListTargetsByRule\"\n ],\n Resource: [\"*\"]\n }\n ]\n }\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAMA,MAAMA,kBAAkB,GAAG,eAA3B;AACA,MAAMC,kBAAkB,GAAI,GAAED,kBAAmB,yBAAjD;AACA,MAAME,qBAAqB,GAAI,GAAEF,kBAAmB,wBAApD;AACA,MAAMG,eAAe,GAAI,GAAEH,kBAAmB,aAA9C;AACA,MAAMI,iBAAiB,GAAI,GAAEJ,kBAAmB,oBAAhD;AAIO,MAAMK,eAAe,GAAG,IAAAC,wBAAA,EAAgB;EAC3CC,IAAI,EAAE,iBADqC;;EAE3CC,MAAM,CAACC,GAAD,EAAiBC,MAAjB,EAA+C;IACjD,MAAMC,aAAa,GAAGC,yBAAyB,CAACH,GAAD,EAAMC,MAAN,CAA/C;IACA,MAAMG,cAAc,GAAGC,0BAA0B,CAACL,GAAD,EAAME,aAAa,CAACI,MAAd,CAAqBC,MAA3B,EAAmCN,MAAnC,CAAjD,CAFiD,CAIjD;;IACA,MAAMO,SAAS,GAAGR,GAAG,CAACS,WAAJ,CAAgBC,GAAG,CAACC,UAAJ,CAAeC,SAA/B,EAA0C;MACxDd,IAAI,EAAEJ,eADkD;MAExDK,MAAM,EAAE;QACJc,WAAW,EAAG,iFAD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QAVd,CAPO,EAsBP;UACIH,GAAG,EAAE,kBADT;UAEIjC,MAAM,EAAE,OAFZ;UAGIH,MAAM,EAAE,CACJ,mBADI,EAEJ,mBAFI,EAGJ,gBAHI,EAIJ,kBAJI,EAKJ,sBALI,EAMJ,0BANI,CAHZ;UAWIqC,QAAQ,EAAE,CAAC,GAAD;QAXd,CAtBO;MAFP;IAFJ;EAF2B,CAAhC,CAAP;AA6CH"}
|
|
1
|
+
{"version":3,"names":["LAMBDA_NAME_PREFIX","CREATE_RULE_LAMBDA","EXECUTE_ACTION_LAMBDA","EVENT_RULE_NAME","EVENT_RULE_TARGET","ApiApwScheduler","createAppModule","name","config","app","params","executeAction","createExecuteActionLambda","scheduleAction","createScheduleActionLambda","lambda","output","eventRule","addResource","aws","cloudwatch","EventRule","description","scheduleExpression","isEnabled","Permission","action","function","arn","principal","statementId","eventTarget","EventTarget","rule","role","iam","Role","assumeRolePolicy","Version","Statement","Action","Principal","Service","Effect","meta","isLambdaFunctionRole","policy","createExecuteActionLambdaPolicy","RolePolicyAttachment","policyArn","ManagedPolicy","AWSLambdaBasicExecutionRole","Function","runtime","handler","timeout","memorySize","code","pulumi","asset","AssetArchive","FileArchive","path","join","paths","workspace","environment","variables","getCommonLambdaEnvVariables","apply","value","env","core","getModule","CoreOutput","Policy","Sid","Resource","interpolate","primaryDynamodbTableArn","executeLambda","createScheduleActionLambdaPolicy","APW_SCHEDULER_EXECUTE_ACTION_HANDLER"],"sources":["ApiApwScheduler.ts"],"sourcesContent":["import path from \"path\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as aws from \"@pulumi/aws\";\nimport { createAppModule, PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\nimport { CoreOutput } from \"../common\";\nimport { getCommonLambdaEnvVariables } from \"../lambdaUtils\";\n\ninterface ScheduleActionParams {\n env: Record<string, any>;\n}\n\nconst LAMBDA_NAME_PREFIX = \"apw-scheduler\";\nconst CREATE_RULE_LAMBDA = `${LAMBDA_NAME_PREFIX}-schedule-action-lambda`;\nconst EXECUTE_ACTION_LAMBDA = `${LAMBDA_NAME_PREFIX}-execute-action-lambda`;\nconst EVENT_RULE_NAME = `${LAMBDA_NAME_PREFIX}-event-rule`;\nconst EVENT_RULE_TARGET = `${LAMBDA_NAME_PREFIX}-event-rule-target`;\n\nexport type ApiApwScheduler = PulumiAppModule<typeof ApiApwScheduler>;\n\nexport const ApiApwScheduler = createAppModule({\n name: \"ApiApwScheduler\",\n config(app: PulumiApp, params: ScheduleActionParams) {\n const executeAction = createExecuteActionLambda(app, params);\n const scheduleAction = createScheduleActionLambda(app, executeAction.lambda.output, params);\n\n // Create event rule.\n const eventRule = app.addResource(aws.cloudwatch.EventRule, {\n name: EVENT_RULE_NAME,\n config: {\n description: `Enable us to schedule an action in publishing workflow at a particular datetime`,\n scheduleExpression: \"cron(* * * * ? 2000)\",\n isEnabled: true\n }\n });\n\n // Add required permission to the target lambda.\n app.addResource(aws.lambda.Permission, {\n name: \"eventTargetPermission\",\n config: {\n action: \"lambda:InvokeFunction\",\n function: scheduleAction.lambda.output.arn,\n principal: \"events.amazonaws.com\",\n statementId: \"allow-rule-invoke-\" + EVENT_RULE_NAME\n }\n });\n\n // Add lambda as target to the event rule.\n const eventTarget = app.addResource(aws.cloudwatch.EventTarget, {\n name: EVENT_RULE_TARGET,\n config: {\n rule: eventRule.output.name,\n arn: scheduleAction.lambda.output.arn\n }\n });\n\n return {\n executeAction,\n scheduleAction,\n eventRule,\n eventTarget\n };\n }\n});\n\nfunction createExecuteActionLambda(app: PulumiApp, params: ScheduleActionParams) {\n const role = app.addResource(aws.iam.Role, {\n name: `${EXECUTE_ACTION_LAMBDA}-role`,\n config: {\n assumeRolePolicy: {\n Version: \"2012-10-17\",\n Statement: [\n {\n Action: \"sts:AssumeRole\",\n Principal: {\n Service: \"lambda.amazonaws.com\"\n },\n Effect: \"Allow\"\n }\n ]\n }\n },\n meta: { isLambdaFunctionRole: true }\n });\n\n const policy = createExecuteActionLambdaPolicy(app);\n\n app.addResource(aws.iam.RolePolicyAttachment, {\n name: `${EXECUTE_ACTION_LAMBDA}-role-policy-attachment`,\n config: {\n role: role.output,\n policyArn: policy.output.arn\n }\n });\n\n app.addResource(aws.iam.RolePolicyAttachment, {\n name: `${EXECUTE_ACTION_LAMBDA}-AWSLambdaBasicExecutionRole`,\n config: {\n role: role.output,\n policyArn: aws.iam.ManagedPolicy.AWSLambdaBasicExecutionRole\n }\n });\n\n const lambda = app.addResource(aws.lambda.Function, {\n name: EXECUTE_ACTION_LAMBDA,\n config: {\n role: role.output.arn,\n runtime: \"nodejs14.x\",\n handler: \"handler.handler\",\n timeout: 60,\n memorySize: 128,\n description: \"Handle execute action workflow in apw scheduler\",\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"apw/executeAction/build\")\n )\n }),\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n ...params.env\n }))\n }\n }\n });\n\n return {\n role,\n policy,\n lambda\n };\n}\n\nfunction createExecuteActionLambdaPolicy(app: PulumiApp) {\n const core = app.getModule(CoreOutput);\n\n return app.addResource(aws.iam.Policy, {\n name: \"ApwSchedulerExecuteActionLambdaPolicy\",\n config: {\n description: \"This policy enables access to cloudwatch event and lambda invocation\",\n policy: {\n Version: \"2012-10-17\",\n Statement: [\n {\n Sid: \"PermissionLambda\",\n Effect: \"Allow\",\n Action: [\"lambda:InvokeFunction\"],\n Resource: [\"*\"]\n },\n {\n Sid: \"PermissionDynamoDB\",\n Effect: \"Allow\",\n Action: [\"dynamodb:Query\", \"dynamodb:GetItem\", \"dynamodb:DeleteItem\"],\n Resource: [\n pulumi.interpolate`${core.primaryDynamodbTableArn}`,\n pulumi.interpolate`${core.primaryDynamodbTableArn}/*`\n ]\n }\n ]\n }\n }\n });\n}\n\nfunction createScheduleActionLambda(\n app: PulumiApp,\n executeLambda: pulumi.Output<aws.lambda.Function>,\n params: ScheduleActionParams\n) {\n const role = app.addResource(aws.iam.Role, {\n name: `${CREATE_RULE_LAMBDA}-role`,\n config: {\n assumeRolePolicy: {\n Version: \"2012-10-17\",\n Statement: [\n {\n Action: \"sts:AssumeRole\",\n Principal: {\n Service: \"lambda.amazonaws.com\"\n },\n Effect: \"Allow\"\n }\n ]\n }\n },\n meta: { isLambdaFunctionRole: true }\n });\n\n const policy = createScheduleActionLambdaPolicy(app);\n\n app.addResource(aws.iam.RolePolicyAttachment, {\n name: `${CREATE_RULE_LAMBDA}-role-policy-attachment`,\n config: {\n role: role.output,\n policyArn: policy.output.arn\n }\n });\n\n app.addResource(aws.iam.RolePolicyAttachment, {\n name: `${CREATE_RULE_LAMBDA}-AWSLambdaBasicExecutionRole`,\n config: {\n role: role.output,\n policyArn: aws.iam.ManagedPolicy.AWSLambdaBasicExecutionRole\n }\n });\n\n const lambda = app.addResource(aws.lambda.Function, {\n name: CREATE_RULE_LAMBDA,\n config: {\n role: role.output.arn,\n runtime: \"nodejs14.x\",\n handler: \"handler.handler\",\n timeout: 60,\n memorySize: 128,\n description: \"Handle schedule action workflow in apw scheduler\",\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"apw/scheduleAction/build\")\n )\n }),\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n ...params.env,\n APW_SCHEDULER_EXECUTE_ACTION_HANDLER: executeLambda.arn\n // RULE_NAME: this.eventRule.name.apply(name => name),\n // RULE_TARGET_ID: this.eventTarget.targetId.apply(id => id)\n }))\n }\n }\n });\n\n return {\n role,\n policy,\n lambda\n };\n}\n\nfunction createScheduleActionLambdaPolicy(app: PulumiApp) {\n const core = app.getModule(CoreOutput);\n\n return app.addResource(aws.iam.Policy, {\n name: \"ApwSchedulerScheduleActionLambdaPolicy\",\n config: {\n description: \"This policy enables access to cloudwatch event and lambda invocation\",\n policy: {\n Version: \"2012-10-17\",\n Statement: [\n {\n Sid: \"PermissionLambda\",\n Effect: \"Allow\",\n Action: [\"lambda:InvokeFunction\"],\n Resource: [\"*\"]\n },\n {\n Sid: \"PermissionDynamoDB\",\n Effect: \"Allow\",\n Action: [\n \"dynamodb:PutItem\",\n \"dynamodb:Query\",\n \"dynamodb:GetItem\",\n \"dynamodb:UpdateItem\",\n \"dynamodb:DeleteItem\"\n ],\n Resource: [\n pulumi.interpolate`${core.primaryDynamodbTableArn}`,\n pulumi.interpolate`${core.primaryDynamodbTableArn}/*`\n ]\n },\n {\n Sid: \"PermissionEvents\",\n Effect: \"Allow\",\n Action: [\n \"events:DeleteRule\",\n \"events:PutTargets\",\n \"events:PutRule\",\n \"events:ListRules\",\n \"events:RemoveTargets\",\n \"events:ListTargetsByRule\"\n ],\n Resource: [\"*\"]\n }\n ]\n }\n }\n });\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAMA,MAAMA,kBAAkB,GAAG,eAAe;AAC1C,MAAMC,kBAAkB,GAAI,GAAED,kBAAmB,yBAAwB;AACzE,MAAME,qBAAqB,GAAI,GAAEF,kBAAmB,wBAAuB;AAC3E,MAAMG,eAAe,GAAI,GAAEH,kBAAmB,aAAY;AAC1D,MAAMI,iBAAiB,GAAI,GAAEJ,kBAAmB,oBAAmB;AAI5D,MAAMK,eAAe,GAAG,IAAAC,wBAAe,EAAC;EAC3CC,IAAI,EAAE,iBAAiB;EACvBC,MAAM,CAACC,GAAc,EAAEC,MAA4B,EAAE;IACjD,MAAMC,aAAa,GAAGC,yBAAyB,CAACH,GAAG,EAAEC,MAAM,CAAC;IAC5D,MAAMG,cAAc,GAAGC,0BAA0B,CAACL,GAAG,EAAEE,aAAa,CAACI,MAAM,CAACC,MAAM,EAAEN,MAAM,CAAC;;IAE3F;IACA,MAAMO,SAAS,GAAGR,GAAG,CAACS,WAAW,CAACC,GAAG,CAACC,UAAU,CAACC,SAAS,EAAE;MACxDd,IAAI,EAAEJ,eAAe;MACrBK,MAAM,EAAE;QACJc,WAAW,EAAG,iFAAgF;Q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,QAAQ,EAAE,CAAC,GAAG;QAClB,CAAC;MAET;IACJ;EACJ,CAAC,CAAC;AACN"}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.ApiCloudfront = void 0;
|
|
9
|
-
|
|
10
8
|
var aws = _interopRequireWildcard(require("@pulumi/aws"));
|
|
11
|
-
|
|
12
9
|
var _pulumi = require("@webiny/pulumi");
|
|
13
|
-
|
|
14
10
|
var _ApiGateway = require("./ApiGateway");
|
|
15
|
-
|
|
16
11
|
const ApiCloudfront = (0, _pulumi.createAppModule)({
|
|
17
12
|
name: "ApiCloudfront",
|
|
18
|
-
|
|
19
13
|
config(app) {
|
|
20
14
|
const gateway = app.getModule(_ApiGateway.ApiGateway);
|
|
21
15
|
return app.addResource(aws.cloudfront.Distribution, {
|
|
@@ -96,6 +90,5 @@ const ApiCloudfront = (0, _pulumi.createAppModule)({
|
|
|
96
90
|
}
|
|
97
91
|
});
|
|
98
92
|
}
|
|
99
|
-
|
|
100
93
|
});
|
|
101
94
|
exports.ApiCloudfront = ApiCloudfront;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ApiCloudfront","createAppModule","name","config","app","gateway","getModule","ApiGateway","addResource","aws","cloudfront","Distribution","waitForDeployment","isIpv6Enabled","enabled","defaultCacheBehavior","compress","allowedMethods","cachedMethods","forwardedValues","cookies","forward","headers","queryString","minTtl","defaultTtl","maxTtl","targetOriginId","api","output","viewerProtocolPolicy","orderedCacheBehaviors","pathPattern","origins","domainName","stage","invokeUrl","apply","url","URL","hostname","originPath","pathname","originId","customOriginConfig","httpPort","httpsPort","originProtocolPolicy","originSslProtocols","restrictions","geoRestriction","restrictionType","viewerCertificate","cloudfrontDefaultCertificate"],"sources":["ApiCloudfront.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport { createAppModule, PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\n\nimport { ApiGateway } from \"./ApiGateway\";\n\nexport type ApiCloudfront = PulumiAppModule<typeof ApiCloudfront>;\n\nexport const ApiCloudfront = createAppModule({\n name: \"ApiCloudfront\",\n config(app: PulumiApp) {\n const gateway = app.getModule(ApiGateway);\n\n return app.addResource(aws.cloudfront.Distribution, {\n name: \"api-cloudfront\",\n config: {\n waitForDeployment: false,\n isIpv6Enabled: true,\n enabled: true,\n defaultCacheBehavior: {\n compress: true,\n allowedMethods: [\"GET\", \"HEAD\", \"OPTIONS\", \"PUT\", \"POST\", \"PATCH\", \"DELETE\"],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies: {\n forward: \"none\"\n },\n headers: [\"Accept\", \"Accept-Language\"],\n queryString: true\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 0,\n maxTtl: 86400,\n targetOriginId: gateway.api.output.name,\n viewerProtocolPolicy: \"allow-all\"\n },\n orderedCacheBehaviors: [\n {\n compress: true,\n allowedMethods: [\n \"GET\",\n \"HEAD\",\n \"OPTIONS\",\n \"PUT\",\n \"POST\",\n \"PATCH\",\n \"DELETE\"\n ],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies: {\n forward: \"none\"\n },\n headers: [\"Accept\", \"Accept-Language\"],\n queryString: true\n },\n pathPattern: \"/cms*\",\n viewerProtocolPolicy: \"allow-all\",\n targetOriginId: gateway.api.output.name\n },\n {\n allowedMethods: [\n \"GET\",\n \"HEAD\",\n \"OPTIONS\",\n \"PUT\",\n \"POST\",\n \"PATCH\",\n \"DELETE\"\n ],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies: {\n forward: \"none\"\n },\n headers: [\"Accept\", \"Accept-Language\"],\n queryString: true\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 0,\n maxTtl: 2592000,\n pathPattern: \"/files/*\",\n viewerProtocolPolicy: \"allow-all\",\n targetOriginId: gateway.api.output.name\n }\n ],\n origins: [\n {\n domainName: gateway.stage.output.invokeUrl.apply(\n (url: string) => new URL(url).hostname\n ),\n originPath: gateway.stage.output.invokeUrl.apply(\n (url: string) => new URL(url).pathname\n ),\n originId: gateway.api.output.name,\n customOriginConfig: {\n httpPort: 80,\n httpsPort: 443,\n originProtocolPolicy: \"https-only\",\n originSslProtocols: [\"TLSv1.2\"]\n }\n }\n ],\n restrictions: {\n geoRestriction: {\n restrictionType: \"none\"\n }\n },\n viewerCertificate: {\n cloudfrontDefaultCertificate: true\n }\n }\n });\n }\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["ApiCloudfront","createAppModule","name","config","app","gateway","getModule","ApiGateway","addResource","aws","cloudfront","Distribution","waitForDeployment","isIpv6Enabled","enabled","defaultCacheBehavior","compress","allowedMethods","cachedMethods","forwardedValues","cookies","forward","headers","queryString","minTtl","defaultTtl","maxTtl","targetOriginId","api","output","viewerProtocolPolicy","orderedCacheBehaviors","pathPattern","origins","domainName","stage","invokeUrl","apply","url","URL","hostname","originPath","pathname","originId","customOriginConfig","httpPort","httpsPort","originProtocolPolicy","originSslProtocols","restrictions","geoRestriction","restrictionType","viewerCertificate","cloudfrontDefaultCertificate"],"sources":["ApiCloudfront.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport { createAppModule, PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\n\nimport { ApiGateway } from \"./ApiGateway\";\n\nexport type ApiCloudfront = PulumiAppModule<typeof ApiCloudfront>;\n\nexport const ApiCloudfront = createAppModule({\n name: \"ApiCloudfront\",\n config(app: PulumiApp) {\n const gateway = app.getModule(ApiGateway);\n\n return app.addResource(aws.cloudfront.Distribution, {\n name: \"api-cloudfront\",\n config: {\n waitForDeployment: false,\n isIpv6Enabled: true,\n enabled: true,\n defaultCacheBehavior: {\n compress: true,\n allowedMethods: [\"GET\", \"HEAD\", \"OPTIONS\", \"PUT\", \"POST\", \"PATCH\", \"DELETE\"],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies: {\n forward: \"none\"\n },\n headers: [\"Accept\", \"Accept-Language\"],\n queryString: true\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 0,\n maxTtl: 86400,\n targetOriginId: gateway.api.output.name,\n viewerProtocolPolicy: \"allow-all\"\n },\n orderedCacheBehaviors: [\n {\n compress: true,\n allowedMethods: [\n \"GET\",\n \"HEAD\",\n \"OPTIONS\",\n \"PUT\",\n \"POST\",\n \"PATCH\",\n \"DELETE\"\n ],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies: {\n forward: \"none\"\n },\n headers: [\"Accept\", \"Accept-Language\"],\n queryString: true\n },\n pathPattern: \"/cms*\",\n viewerProtocolPolicy: \"allow-all\",\n targetOriginId: gateway.api.output.name\n },\n {\n allowedMethods: [\n \"GET\",\n \"HEAD\",\n \"OPTIONS\",\n \"PUT\",\n \"POST\",\n \"PATCH\",\n \"DELETE\"\n ],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies: {\n forward: \"none\"\n },\n headers: [\"Accept\", \"Accept-Language\"],\n queryString: true\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 0,\n maxTtl: 2592000,\n pathPattern: \"/files/*\",\n viewerProtocolPolicy: \"allow-all\",\n targetOriginId: gateway.api.output.name\n }\n ],\n origins: [\n {\n domainName: gateway.stage.output.invokeUrl.apply(\n (url: string) => new URL(url).hostname\n ),\n originPath: gateway.stage.output.invokeUrl.apply(\n (url: string) => new URL(url).pathname\n ),\n originId: gateway.api.output.name,\n customOriginConfig: {\n httpPort: 80,\n httpsPort: 443,\n originProtocolPolicy: \"https-only\",\n originSslProtocols: [\"TLSv1.2\"]\n }\n }\n ],\n restrictions: {\n geoRestriction: {\n restrictionType: \"none\"\n }\n },\n viewerCertificate: {\n cloudfrontDefaultCertificate: true\n }\n }\n });\n }\n});\n"],"mappings":";;;;;;;AAAA;AACA;AAEA;AAIO,MAAMA,aAAa,GAAG,IAAAC,uBAAe,EAAC;EACzCC,IAAI,EAAE,eAAe;EACrBC,MAAM,CAACC,GAAc,EAAE;IACnB,MAAMC,OAAO,GAAGD,GAAG,CAACE,SAAS,CAACC,sBAAU,CAAC;IAEzC,OAAOH,GAAG,CAACI,WAAW,CAACC,GAAG,CAACC,UAAU,CAACC,YAAY,EAAE;MAChDT,IAAI,EAAE,gBAAgB;MACtBC,MAAM,EAAE;QACJS,iBAAiB,EAAE,KAAK;QACxBC,aAAa,EAAE,IAAI;QACnBC,OAAO,EAAE,IAAI;QACbC,oBAAoB,EAAE;UAClBC,QAAQ,EAAE,IAAI;UACdC,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC;UAC5EC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC;UACzCC,eAAe,EAAE;YACbC,OAAO,EAAE;cACLC,OAAO,EAAE;YACb,CAAC;YACDC,OAAO,EAAE,CAAC,QAAQ,EAAE,iBAAiB,CAAC;YACtCC,WAAW,EAAE;UACjB,CAAC;UACD;UACAC,MAAM,EAAE,CAAC;UACTC,UAAU,EAAE,CAAC;UACbC,MAAM,EAAE,KAAK;UACbC,cAAc,EAAEtB,OAAO,CAACuB,GAAG,CAACC,MAAM,CAAC3B,IAAI;UACvC4B,oBAAoB,EAAE;QAC1B,CAAC;QACDC,qBAAqB,EAAE,CACnB;UACIf,QAAQ,EAAE,IAAI;UACdC,cAAc,EAAE,CACZ,KAAK,EACL,MAAM,EACN,SAAS,EACT,KA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,EAAEtC,OAAO,CAACuB,GAAG,CAACC,MAAM,CAAC3B,IAAI;UACjC0C,kBAAkB,EAAE;YAChBC,QAAQ,EAAE,EAAE;YACZC,SAAS,EAAE,GAAG;YACdC,oBAAoB,EAAE,YAAY;YAClCC,kBAAkB,EAAE,CAAC,SAAS;UAClC;QACJ,CAAC,CACJ;QACDC,YAAY,EAAE;UACVC,cAAc,EAAE;YACZC,eAAe,EAAE;UACrB;QACJ,CAAC;QACDC,iBAAiB,EAAE;UACfC,4BAA4B,EAAE;QAClC;MACJ;IACJ,CAAC,CAAC;EACN;AACJ,CAAC,CAAC;AAAC"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { PulumiAppModule } from "@webiny/pulumi";
|
|
2
2
|
export declare type ApiFileManager = PulumiAppModule<typeof ApiFileManager>;
|
|
3
|
+
interface ApiFileManagerConfig {
|
|
4
|
+
env: Record<string, any>;
|
|
5
|
+
}
|
|
3
6
|
export declare const ApiFileManager: import("@webiny/pulumi").PulumiAppModuleDefinition<{
|
|
4
7
|
functions: {
|
|
5
8
|
transform: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/lambda/function").Function>;
|
|
@@ -7,4 +10,5 @@ export declare const ApiFileManager: import("@webiny/pulumi").PulumiAppModuleDef
|
|
|
7
10
|
download: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/lambda/function").Function>;
|
|
8
11
|
};
|
|
9
12
|
bucketNotification: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/s3/bucketNotification").BucketNotification>;
|
|
10
|
-
},
|
|
13
|
+
}, ApiFileManagerConfig>;
|
|
14
|
+
export {};
|
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.ApiFileManager = void 0;
|
|
11
|
-
|
|
12
9
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
|
-
|
|
14
10
|
var _path = _interopRequireDefault(require("path"));
|
|
15
|
-
|
|
16
11
|
var pulumi = _interopRequireWildcard(require("@pulumi/pulumi"));
|
|
17
|
-
|
|
18
12
|
var aws = _interopRequireWildcard(require("@pulumi/aws"));
|
|
19
|
-
|
|
20
13
|
var _awsLayers = require("@webiny/aws-layers");
|
|
21
|
-
|
|
22
14
|
var _pulumi2 = require("@webiny/pulumi");
|
|
23
|
-
|
|
24
15
|
var _lambdaUtils = require("../lambdaUtils");
|
|
25
|
-
|
|
26
16
|
var _common = require("../common");
|
|
27
|
-
|
|
28
17
|
var _awsUtils = require("../awsUtils");
|
|
29
|
-
|
|
30
18
|
// @ts-ignore
|
|
19
|
+
|
|
31
20
|
const ApiFileManager = (0, _pulumi2.createAppModule)({
|
|
32
21
|
name: "ApiFileManager",
|
|
33
|
-
|
|
34
|
-
config(app) {
|
|
22
|
+
config(app, config) {
|
|
35
23
|
const core = app.getModule(_common.CoreOutput);
|
|
36
24
|
const accountId = (0, _awsUtils.getAwsAccountId)(app);
|
|
37
25
|
const policy = createFileManagerLambdaPolicy(app);
|
|
@@ -96,7 +84,7 @@ const ApiFileManager = (0, _pulumi2.createAppModule)({
|
|
|
96
84
|
variables: (0, _lambdaUtils.getCommonLambdaEnvVariables)().apply(value => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, value), {}, {
|
|
97
85
|
S3_BUCKET: core.fileManagerBucketId,
|
|
98
86
|
IMAGE_TRANSFORMER_FUNCTION: transform.output.arn
|
|
99
|
-
}))
|
|
87
|
+
}, config.env))
|
|
100
88
|
},
|
|
101
89
|
vpcConfig: app.getModule(_common.VpcConfig).functionVpcConfig
|
|
102
90
|
}
|
|
@@ -137,10 +125,8 @@ const ApiFileManager = (0, _pulumi2.createAppModule)({
|
|
|
137
125
|
bucketNotification
|
|
138
126
|
};
|
|
139
127
|
}
|
|
140
|
-
|
|
141
128
|
});
|
|
142
129
|
exports.ApiFileManager = ApiFileManager;
|
|
143
|
-
|
|
144
130
|
function createFileManagerLambdaPolicy(app) {
|
|
145
131
|
const core = app.getModule(_common.CoreOutput);
|
|
146
132
|
return app.addResource(aws.iam.Policy, {
|
|
@@ -159,6 +145,11 @@ function createFileManagerLambdaPolicy(app) {
|
|
|
159
145
|
Effect: "Allow",
|
|
160
146
|
Action: ["s3:DeleteObject", "s3:PutObject", "s3:GetObject", "s3:ListBucket"],
|
|
161
147
|
Resource: [pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}`, pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}/*`]
|
|
148
|
+
}, {
|
|
149
|
+
Sid: "PermissionForDynamoDB",
|
|
150
|
+
Effect: "Allow",
|
|
151
|
+
Action: ["dynamodb:GetItem", "dynamodb:Query"],
|
|
152
|
+
Resource: [pulumi.interpolate`${core.primaryDynamodbTableArn}`, pulumi.interpolate`${core.primaryDynamodbTableArn}/*`]
|
|
162
153
|
}]
|
|
163
154
|
}
|
|
164
155
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ApiFileManager","createAppModule","name","config","app","core","getModule","CoreOutput","accountId","getAwsAccountId","policy","createFileManagerLambdaPolicy","role","createLambdaRole","output","transform","addResource","aws","lambda","Function","handler","timeout","runtime","memorySize","arn","description","code","pulumi","asset","AssetArchive","FileArchive","path","join","paths","workspace","layers","getLayerArn","environment","variables","getCommonLambdaEnvVariables","apply","value","S3_BUCKET","fileManagerBucketId","vpcConfig","VpcConfig","functionVpcConfig","manage","download","IMAGE_TRANSFORMER_FUNCTION","manageS3LambdaPermission","Permission","action","function","principal","sourceArn","interpolate","sourceAccount","opts","dependsOn","bucketNotification","s3","BucketNotification","bucket","lambdaFunctions","lambdaFunctionArn","events","functions","iam","Policy","Version","Statement","Sid","Effect","Action","Resource"],"sources":["ApiFileManager.ts"],"sourcesContent":["import path from \"path\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as aws from \"@pulumi/aws\";\n\n// @ts-ignore\nimport { getLayerArn } from \"@webiny/aws-layers\";\nimport { createAppModule, PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\n\nimport { createLambdaRole, getCommonLambdaEnvVariables } from \"../lambdaUtils\";\nimport { CoreOutput, VpcConfig } from \"../common\";\nimport { getAwsAccountId } from \"~/apps/awsUtils\";\n\nexport type ApiFileManager = PulumiAppModule<typeof ApiFileManager>;\n\nexport const ApiFileManager = createAppModule({\n name: \"ApiFileManager\",\n config(app: PulumiApp) {\n const core = app.getModule(CoreOutput);\n const accountId = getAwsAccountId(app);\n\n const policy = createFileManagerLambdaPolicy(app);\n const role = createLambdaRole(app, {\n name: \"fm-lambda-role\",\n policy: policy.output\n });\n\n const transform = app.addResource(aws.lambda.Function, {\n name: \"fm-image-transformer\",\n config: {\n handler: \"handler.handler\",\n timeout: 30,\n runtime: \"nodejs14.x\",\n memorySize: 1600,\n role: role.output.arn,\n description: \"Performs image optimization, resizing, etc.\",\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"fileManager/transform/build\")\n )\n }),\n layers: [getLayerArn(\"sharp\")],\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n S3_BUCKET: core.fileManagerBucketId\n }))\n },\n vpcConfig: app.getModule(VpcConfig).functionVpcConfig\n }\n });\n\n const manage = app.addResource(aws.lambda.Function, {\n name: \"fm-manage\",\n config: {\n role: role.output.arn,\n runtime: \"nodejs14.x\",\n handler: \"handler.handler\",\n timeout: 30,\n memorySize: 512,\n description: \"Triggered when a file is deleted.\",\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"fileManager/manage/build\")\n )\n }),\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n S3_BUCKET: core.fileManagerBucketId\n }))\n },\n vpcConfig: app.getModule(VpcConfig).functionVpcConfig\n }\n });\n\n const download = app.addResource(aws.lambda.Function, {\n name: \"fm-download\",\n config: {\n role: role.output.arn,\n runtime: \"nodejs14.x\",\n handler: \"handler.handler\",\n timeout: 30,\n memorySize: 512,\n description: \"Serves previously uploaded files.\",\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"fileManager/download/build\")\n )\n }),\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n S3_BUCKET: core.fileManagerBucketId,\n IMAGE_TRANSFORMER_FUNCTION: transform.output.arn\n }))\n },\n vpcConfig: app.getModule(VpcConfig).functionVpcConfig\n }\n });\n\n const manageS3LambdaPermission = app.addResource(aws.lambda.Permission, {\n name: \"fm-manage-s3-lambda-permission\",\n config: {\n action: \"lambda:InvokeFunction\",\n function: manage.output.arn,\n principal: \"s3.amazonaws.com\",\n sourceArn: pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}`,\n sourceAccount: accountId\n },\n opts: {\n dependsOn: [manage.output]\n }\n });\n\n const bucketNotification = app.addResource(aws.s3.BucketNotification, {\n name: \"bucketNotification\",\n config: {\n bucket: core.fileManagerBucketId,\n lambdaFunctions: [\n {\n lambdaFunctionArn: manage.output.arn,\n events: [\"s3:ObjectRemoved:*\"]\n }\n ]\n },\n opts: {\n dependsOn: [manage.output, manageS3LambdaPermission.output]\n }\n });\n\n const functions = {\n transform,\n manage,\n download\n };\n\n return {\n functions,\n bucketNotification\n };\n }\n});\n\nfunction createFileManagerLambdaPolicy(app: PulumiApp) {\n const core = app.getModule(CoreOutput);\n\n return app.addResource(aws.iam.Policy, {\n name: \"FileManagerLambdaPolicy\",\n config: {\n description: \"This policy enables access to Lambda and S3\",\n policy: {\n Version: \"2012-10-17\",\n Statement: [\n {\n Sid: \"PermissionForLambda\",\n Effect: \"Allow\",\n Action: \"lambda:InvokeFunction\",\n Resource: \"*\"\n },\n {\n Sid: \"PermissionForS3\",\n Effect: \"Allow\",\n Action: [\n \"s3:DeleteObject\",\n \"s3:PutObject\",\n \"s3:GetObject\",\n \"s3:ListBucket\"\n ],\n Resource: [\n pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}`,\n pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}/*`\n ]\n }\n ]\n }\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAGA;;AACA;;AAEA;;AACA;;AACA;;AANA;AAUO,MAAMA,cAAc,GAAG,IAAAC,wBAAA,EAAgB;EAC1CC,IAAI,EAAE,gBADoC;;EAE1CC,MAAM,CAACC,GAAD,EAAiB;IACnB,MAAMC,IAAI,GAAGD,GAAG,CAACE,SAAJ,CAAcC,kBAAd,CAAb;IACA,MAAMC,SAAS,GAAG,IAAAC,yBAAA,EAAgBL,GAAhB,CAAlB;IAEA,MAAMM,MAAM,GAAGC,6BAA6B,CAACP,GAAD,CAA5C;IACA,MAAMQ,IAAI,GAAG,IAAAC,6BAAA,EAAiBT,GAAjB,EAAsB;MAC/BF,IAAI,EAAE,gBADyB;MAE/BQ,MAAM,EAAEA,MAAM,CAACI;IAFgB,CAAtB,CAAb;IAKA,MAAMC,SAAS,GAAGX,GAAG,CAACY,WAAJ,CAAgBC,GAAG,CAACC,MAAJ,CAAWC,QAA3B,EAAqC;MACnDjB,IAAI,EAAE,sBAD6C;MAEnDC,MAAM,EAAE;QACJiB,OAAO,EAAE,iBADL;QAEJC,OAAO,EAAE,EAFL;QAGJC,OAAO,EAAE,YAHL;QAIJC,UAAU,EAAE,IAJR;QAKJX,IAAI,EAAEA,IAAI,CAACE,MAAL,CAAYU,GALd;QAMJC,WAAW,EAAE,6CANT;QAOJC,IAAI,EAAE,IAAIC,MAAM,CAACC,KAAP,CAAaC,YAAjB,CAA8B;UAChC,KAAK,IAA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;UAGIC,MAAM,EAAE,CACJ,iBADI,EAEJ,cAFI,EAGJ,cAHI,EAIJ,eAJI,CAHZ;UASIC,QAAQ,EAAE,CACNhD,MAAM,CAAC6B,WAAY,gBAAenD,IAAI,CAACsC,mBAAoB,EADrD,EAENhB,MAAM,CAAC6B,WAAY,gBAAenD,IAAI,CAACsC,mBAAoB,IAFrD;QATd,CAPO;MAFP;IAFJ;EAF2B,CAAhC,CAAP;AA+BH"}
|
|
1
|
+
{"version":3,"names":["ApiFileManager","createAppModule","name","config","app","core","getModule","CoreOutput","accountId","getAwsAccountId","policy","createFileManagerLambdaPolicy","role","createLambdaRole","output","transform","addResource","aws","lambda","Function","handler","timeout","runtime","memorySize","arn","description","code","pulumi","asset","AssetArchive","FileArchive","path","join","paths","workspace","layers","getLayerArn","environment","variables","getCommonLambdaEnvVariables","apply","value","S3_BUCKET","fileManagerBucketId","vpcConfig","VpcConfig","functionVpcConfig","manage","download","IMAGE_TRANSFORMER_FUNCTION","env","manageS3LambdaPermission","Permission","action","function","principal","sourceArn","interpolate","sourceAccount","opts","dependsOn","bucketNotification","s3","BucketNotification","bucket","lambdaFunctions","lambdaFunctionArn","events","functions","iam","Policy","Version","Statement","Sid","Effect","Action","Resource","primaryDynamodbTableArn"],"sources":["ApiFileManager.ts"],"sourcesContent":["import path from \"path\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as aws from \"@pulumi/aws\";\n\n// @ts-ignore\nimport { getLayerArn } from \"@webiny/aws-layers\";\nimport { createAppModule, PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\n\nimport { createLambdaRole, getCommonLambdaEnvVariables } from \"../lambdaUtils\";\nimport { CoreOutput, VpcConfig } from \"../common\";\nimport { getAwsAccountId } from \"~/apps/awsUtils\";\n\nexport type ApiFileManager = PulumiAppModule<typeof ApiFileManager>;\n\ninterface ApiFileManagerConfig {\n env: Record<string, any>;\n}\n\nexport const ApiFileManager = createAppModule({\n name: \"ApiFileManager\",\n config(app: PulumiApp, config: ApiFileManagerConfig) {\n const core = app.getModule(CoreOutput);\n const accountId = getAwsAccountId(app);\n\n const policy = createFileManagerLambdaPolicy(app);\n const role = createLambdaRole(app, {\n name: \"fm-lambda-role\",\n policy: policy.output\n });\n\n const transform = app.addResource(aws.lambda.Function, {\n name: \"fm-image-transformer\",\n config: {\n handler: \"handler.handler\",\n timeout: 30,\n runtime: \"nodejs14.x\",\n memorySize: 1600,\n role: role.output.arn,\n description: \"Performs image optimization, resizing, etc.\",\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"fileManager/transform/build\")\n )\n }),\n layers: [getLayerArn(\"sharp\")],\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n S3_BUCKET: core.fileManagerBucketId\n }))\n },\n vpcConfig: app.getModule(VpcConfig).functionVpcConfig\n }\n });\n\n const manage = app.addResource(aws.lambda.Function, {\n name: \"fm-manage\",\n config: {\n role: role.output.arn,\n runtime: \"nodejs14.x\",\n handler: \"handler.handler\",\n timeout: 30,\n memorySize: 512,\n description: \"Triggered when a file is deleted.\",\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"fileManager/manage/build\")\n )\n }),\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n S3_BUCKET: core.fileManagerBucketId\n }))\n },\n vpcConfig: app.getModule(VpcConfig).functionVpcConfig\n }\n });\n\n const download = app.addResource(aws.lambda.Function, {\n name: \"fm-download\",\n config: {\n role: role.output.arn,\n runtime: \"nodejs14.x\",\n handler: \"handler.handler\",\n timeout: 30,\n memorySize: 512,\n description: \"Serves previously uploaded files.\",\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"fileManager/download/build\")\n )\n }),\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n S3_BUCKET: core.fileManagerBucketId,\n IMAGE_TRANSFORMER_FUNCTION: transform.output.arn,\n ...config.env\n }))\n },\n vpcConfig: app.getModule(VpcConfig).functionVpcConfig\n }\n });\n\n const manageS3LambdaPermission = app.addResource(aws.lambda.Permission, {\n name: \"fm-manage-s3-lambda-permission\",\n config: {\n action: \"lambda:InvokeFunction\",\n function: manage.output.arn,\n principal: \"s3.amazonaws.com\",\n sourceArn: pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}`,\n sourceAccount: accountId\n },\n opts: {\n dependsOn: [manage.output]\n }\n });\n\n const bucketNotification = app.addResource(aws.s3.BucketNotification, {\n name: \"bucketNotification\",\n config: {\n bucket: core.fileManagerBucketId,\n lambdaFunctions: [\n {\n lambdaFunctionArn: manage.output.arn,\n events: [\"s3:ObjectRemoved:*\"]\n }\n ]\n },\n opts: {\n dependsOn: [manage.output, manageS3LambdaPermission.output]\n }\n });\n\n const functions = {\n transform,\n manage,\n download\n };\n\n return {\n functions,\n bucketNotification\n };\n }\n});\n\nfunction createFileManagerLambdaPolicy(app: PulumiApp) {\n const core = app.getModule(CoreOutput);\n\n return app.addResource(aws.iam.Policy, {\n name: \"FileManagerLambdaPolicy\",\n config: {\n description: \"This policy enables access to Lambda and S3\",\n policy: {\n Version: \"2012-10-17\",\n Statement: [\n {\n Sid: \"PermissionForLambda\",\n Effect: \"Allow\",\n Action: \"lambda:InvokeFunction\",\n Resource: \"*\"\n },\n {\n Sid: \"PermissionForS3\",\n Effect: \"Allow\",\n Action: [\n \"s3:DeleteObject\",\n \"s3:PutObject\",\n \"s3:GetObject\",\n \"s3:ListBucket\"\n ],\n Resource: [\n pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}`,\n pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}/*`\n ]\n },\n {\n Sid: \"PermissionForDynamoDB\",\n Effect: \"Allow\",\n Action: [\"dynamodb:GetItem\", \"dynamodb:Query\"],\n Resource: [\n pulumi.interpolate`${core.primaryDynamodbTableArn}`,\n pulumi.interpolate`${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C9CC,QAAQ,EAAE,CACNjD,MAAM,CAAC8B,WAAY,GAAEpD,IAAI,CAACwE,uBAAwB,EAAC,EACnDlD,MAAM,CAAC8B,WAAY,GAAEpD,IAAI,CAACwE,uBAAwB,IAAG;QAE7D,CAAC;MAET;IACJ;EACJ,CAAC,CAAC;AACN"}
|
package/apps/api/ApiGateway.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.ApiGateway = void 0;
|
|
9
|
-
|
|
10
8
|
var aws = _interopRequireWildcard(require("@pulumi/aws"));
|
|
11
|
-
|
|
12
9
|
var _pulumi = require("@webiny/pulumi");
|
|
13
|
-
|
|
14
10
|
const ApiGateway = (0, _pulumi.createAppModule)({
|
|
15
11
|
name: "ApiGateway",
|
|
16
|
-
|
|
17
12
|
config(app, routesConfig) {
|
|
18
13
|
const api = app.addResource(aws.apigatewayv2.Api, {
|
|
19
14
|
name: "api-gateway",
|
|
@@ -30,27 +25,22 @@ const ApiGateway = (0, _pulumi.createAppModule)({
|
|
|
30
25
|
}
|
|
31
26
|
});
|
|
32
27
|
const routes = {};
|
|
33
|
-
|
|
34
28
|
for (const name of Object.keys(routesConfig)) {
|
|
35
29
|
addRoute(name, routesConfig[name]);
|
|
36
30
|
}
|
|
37
|
-
|
|
38
31
|
return {
|
|
39
32
|
api,
|
|
40
33
|
stage,
|
|
41
34
|
routes,
|
|
42
35
|
addRoute
|
|
43
36
|
};
|
|
44
|
-
|
|
45
37
|
function addRoute(name, params) {
|
|
46
38
|
const route = createRoute(app, api.output, name, params);
|
|
47
39
|
routes[name] = route;
|
|
48
40
|
}
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
});
|
|
52
43
|
exports.ApiGateway = ApiGateway;
|
|
53
|
-
|
|
54
44
|
function createRoute(app, api, name, params) {
|
|
55
45
|
const integration = app.addResource(aws.apigatewayv2.Integration, {
|
|
56
46
|
name: name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ApiGateway","createAppModule","name","config","app","routesConfig","api","addResource","aws","apigatewayv2","Api","protocolType","description","stage","Stage","apiId","output","id","autoDeploy","routes","Object","keys","addRoute","params","route","createRoute","integration","Integration","integrationType","integrationMethod","method","integrationUri","function","passthroughBehavior","Route","routeKey","path","target","apply","value","permission","lambda","Permission","action","principal","sourceArn","executionArn","arn"],"sources":["ApiGateway.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport { createAppModule, PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\n\nexport interface ApiRouteParams {\n path: pulumi.Input<string>;\n method: pulumi.Input<string>;\n function: pulumi.Input<string>;\n}\n\nexport type ApiGateway = PulumiAppModule<typeof ApiGateway>;\n\nexport const ApiGateway = createAppModule({\n name: \"ApiGateway\",\n config(app: PulumiApp, routesConfig: Record<string, ApiRouteParams>) {\n const api = app.addResource(aws.apigatewayv2.Api, {\n name: \"api-gateway\",\n config: {\n protocolType: \"HTTP\",\n description: \"Main API gateway\"\n }\n });\n\n const stage = app.addResource(aws.apigatewayv2.Stage, {\n name: \"default\",\n config: {\n apiId: api.output.id,\n autoDeploy: true\n }\n });\n\n const routes: Record<string, ReturnType<typeof createRoute>> = {};\n\n for (const name of Object.keys(routesConfig)) {\n addRoute(name, routesConfig[name]);\n }\n\n return {\n api,\n stage,\n routes,\n addRoute\n };\n\n function addRoute(name: string, params: ApiRouteParams) {\n const route = createRoute(app, api.output, name, params);\n routes[name] = route;\n }\n }\n});\n\nfunction createRoute(\n app: PulumiApp,\n api: pulumi.Output<aws.apigatewayv2.Api>,\n name: string,\n params: ApiRouteParams\n) {\n const integration = app.addResource(aws.apigatewayv2.Integration, {\n name: name,\n config: {\n description: \"GraphQL API Integration\",\n apiId: api.id,\n integrationType: \"AWS_PROXY\",\n integrationMethod: params.method,\n integrationUri: params.function,\n passthroughBehavior: \"WHEN_NO_MATCH\"\n }\n });\n\n const route = app.addResource(aws.apigatewayv2.Route, {\n name: name,\n config: {\n apiId: api.id,\n routeKey: `${params.method} ${params.path}`,\n target: integration.output.id.apply(value => `integrations/${value}`)\n }\n });\n\n const permission = app.addResource(aws.lambda.Permission, {\n name: `allow-${name}`,\n config: {\n action: \"lambda:InvokeFunction\",\n function: params.function,\n principal: \"apigateway.amazonaws.com\",\n sourceArn: api.executionArn.apply(arn => `${arn}/*/*${params.path}`)\n }\n });\n\n return {\n integration,\n route,\n permission\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["ApiGateway","createAppModule","name","config","app","routesConfig","api","addResource","aws","apigatewayv2","Api","protocolType","description","stage","Stage","apiId","output","id","autoDeploy","routes","Object","keys","addRoute","params","route","createRoute","integration","Integration","integrationType","integrationMethod","method","integrationUri","function","passthroughBehavior","Route","routeKey","path","target","apply","value","permission","lambda","Permission","action","principal","sourceArn","executionArn","arn"],"sources":["ApiGateway.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport { createAppModule, PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\n\nexport interface ApiRouteParams {\n path: pulumi.Input<string>;\n method: pulumi.Input<string>;\n function: pulumi.Input<string>;\n}\n\nexport type ApiGateway = PulumiAppModule<typeof ApiGateway>;\n\nexport const ApiGateway = createAppModule({\n name: \"ApiGateway\",\n config(app: PulumiApp, routesConfig: Record<string, ApiRouteParams>) {\n const api = app.addResource(aws.apigatewayv2.Api, {\n name: \"api-gateway\",\n config: {\n protocolType: \"HTTP\",\n description: \"Main API gateway\"\n }\n });\n\n const stage = app.addResource(aws.apigatewayv2.Stage, {\n name: \"default\",\n config: {\n apiId: api.output.id,\n autoDeploy: true\n }\n });\n\n const routes: Record<string, ReturnType<typeof createRoute>> = {};\n\n for (const name of Object.keys(routesConfig)) {\n addRoute(name, routesConfig[name]);\n }\n\n return {\n api,\n stage,\n routes,\n addRoute\n };\n\n function addRoute(name: string, params: ApiRouteParams) {\n const route = createRoute(app, api.output, name, params);\n routes[name] = route;\n }\n }\n});\n\nfunction createRoute(\n app: PulumiApp,\n api: pulumi.Output<aws.apigatewayv2.Api>,\n name: string,\n params: ApiRouteParams\n) {\n const integration = app.addResource(aws.apigatewayv2.Integration, {\n name: name,\n config: {\n description: \"GraphQL API Integration\",\n apiId: api.id,\n integrationType: \"AWS_PROXY\",\n integrationMethod: params.method,\n integrationUri: params.function,\n passthroughBehavior: \"WHEN_NO_MATCH\"\n }\n });\n\n const route = app.addResource(aws.apigatewayv2.Route, {\n name: name,\n config: {\n apiId: api.id,\n routeKey: `${params.method} ${params.path}`,\n target: integration.output.id.apply(value => `integrations/${value}`)\n }\n });\n\n const permission = app.addResource(aws.lambda.Permission, {\n name: `allow-${name}`,\n config: {\n action: \"lambda:InvokeFunction\",\n function: params.function,\n principal: \"apigateway.amazonaws.com\",\n sourceArn: api.executionArn.apply(arn => `${arn}/*/*${params.path}`)\n }\n });\n\n return {\n integration,\n route,\n permission\n };\n}\n"],"mappings":";;;;;;;AAAA;AAEA;AAUO,MAAMA,UAAU,GAAG,IAAAC,uBAAe,EAAC;EACtCC,IAAI,EAAE,YAAY;EAClBC,MAAM,CAACC,GAAc,EAAEC,YAA4C,EAAE;IACjE,MAAMC,GAAG,GAAGF,GAAG,CAACG,WAAW,CAACC,GAAG,CAACC,YAAY,CAACC,GAAG,EAAE;MAC9CR,IAAI,EAAE,aAAa;MACnBC,MAAM,EAAE;QACJQ,YAAY,EAAE,MAAM;QACpBC,WAAW,EAAE;MACjB;IACJ,CAAC,CAAC;IAEF,MAAMC,KAAK,GAAGT,GAAG,CAACG,WAAW,CAACC,GAAG,CAACC,YAAY,CAACK,KAAK,EAAE;MAClDZ,IAAI,EAAE,SAAS;MACfC,MAAM,EAAE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