@webiny/pulumi-aws 5.24.0 → 5.25.0-beta.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["WebsiteTenantRouter.ts"],"names":["createFunctionArchive","dynamoDbTable","region","handler","__dirname","source","replace","pulumi","asset","AssetArchive","StringAsset","WebsiteTenantRouter","ComponentResource","constructor","name","config","opts","folder","apiFolder","env","apiEnv","String","process","WEBINY_ENV","inlinePolicies","Promise","all","aws","getCallerIdentity","then","callerIdentity","policy","JSON","stringify","Version","Statement","Sid","Effect","Action","Resource","accountId","role","iam","Role","managedPolicyArns","ManagedPolicies","AWSLambdaBasicExecutionRole","assumeRolePolicy","Principal","Principals","LambdaPrincipal","EdgeLambdaPrincipal","parent","awsUsEast1","Provider","originRequest","lambda","Function","publish","runtime","arn","timeout","memorySize","code","provider","registerOutputs"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;AAYA,SAASA,qBAAT,CAA+B;AAAEC,EAAAA,aAAF;AAAiBC,EAAAA;AAAjB,CAA/B,EAAkE;AAC9D,QAAMC,OAAO,GAAG,sBAAaC,SAAS,GAAG,8BAAzB,EAAyD,OAAzD,CAAhB;AAEA,QAAMC,MAAM,GAAGF,OAAO,CACjBG,OADU,CACF,iBADE,EACiBL,aADjB,EAEVK,OAFU,CAEF,mBAFE,EAEmBJ,MAFnB,CAAf;AAIA,SAAO,IAAIK,MAAM,CAACC,KAAP,CAAaC,YAAjB,CAA8B;AACjC,gBAAY,IAAIF,MAAM,CAACC,KAAP,CAAaE,WAAjB,CAA6BL,MAA7B;AADqB,GAA9B,CAAP;AAGH;;AAEM,MAAMM,mBAAN,SAAkCJ,MAAM,CAACK,iBAAzC,CAA2D;AAG9DC,EAAAA,WAAW,CAACC,IAAD,EAAeC,MAAc,GAAG,EAAhC,EAAoCC,IAAI,GAAG,EAA3C,EAA+C;AACtD,UAAM,gCAAN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EAAE,CACP;AACIG,UAAAA,MAAM,EAAE,gBADZ;AAEIU,UAAAA,SAAS,EAAErB,GAAG,CAACe,GAAJ,CAAQO,UAAR,CAAmBC,eAFlC;AAGIb,UAAAA,MAAM,EAAE;AAHZ,SADO,EAMP;AACIC,UAAAA,MAAM,EAAE,gBADZ;AAEIU,UAAAA,SAAS,EAAErB,GAAG,CAACe,GAAJ,CAAQO,UAAR,CAAmBE,mBAFlC;AAGId,UAAAA,MAAM,EAAE;AAHZ,SANO;AAFG;AAHtB,KAFS,EAqBT;AAAEe,MAAAA,MAAM,EAAE;AAAV,KArBS,CAAb,CA5BsD,CAoDtD;;AACA,UAAMC,UAAU,GAAG,IAAI1B,GAAG,CAAC2B,QAAR,CAAiB,WAAjB,EAA8B;AAAEpD,MAAAA,MAAM,EAAE;AAAV,KAA9B,CAAnB;AAEA,SAAKqD,aAAL,GAAqB,IAAI5B,GAAG,CAAC6B,MAAJ,CAAWC,QAAf,CAChB,GAAE3C,IAAK,iBADS,EAEjB;AACI4C,MAAAA,OAAO,EAAE,IADb;AAEIC,MAAAA,OAAO,EAAE,YAFb;AAGIxD,MAAAA,OAAO,EAAE,eAHb;AAIIsC,MAAAA,IAAI,EAAEA,IAAI,CAACmB,GAJf;AAKIC,MAAAA,OAAO,EAAE,CALb;AAMIC,MAAAA,UAAU,EAAE,GANhB;AAOIC,MAAAA,IAAI,EAAE/D,qBAAqB,CAAC;AAAEE,QAAAA,MAAF;AAAUD,QAAAA;AAAV,OAAD;AAP/B,KAFiB,EAWjB;AAAE+D,MAAAA,QAAQ,EAAEX,UAAZ;AAAwBD,MAAAA,MAAM,EAAE;AAAhC,KAXiB,CAArB;AAcA,SAAKa,eAAL;AACH;;AAzE6D","sourcesContent":["import { readFileSync } from \"fs\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as aws from \"@pulumi/aws\";\nimport { getStackOutput } from \"@webiny/cli-plugin-deploy-pulumi/utils\";\n\ninterface Config {\n apiFolder?: string;\n apiEnv?: string;\n}\n\ninterface Params {\n region: string;\n dynamoDbTable: string;\n}\n\nfunction createFunctionArchive({ dynamoDbTable, region }: Params) {\n const handler = readFileSync(__dirname + \"/functions/origin/request.js\", \"utf-8\");\n\n const source = handler\n .replace(\"{DB_TABLE_NAME}\", dynamoDbTable)\n .replace(\"{DB_TABLE_REGION}\", region);\n\n return new pulumi.asset.AssetArchive({\n \"index.js\": new pulumi.asset.StringAsset(source)\n });\n}\n\nexport class WebsiteTenantRouter extends pulumi.ComponentResource {\n public readonly originRequest: aws.lambda.Function;\n\n constructor(name: string, config: Config = {}, opts = {}) {\n super(\"webiny:aws:WebsiteTenantRouter\", name, {}, opts);\n\n const { region, dynamoDbTable } = getStackOutput({\n folder: config.apiFolder || \"api\",\n env: config.apiEnv || String(process.env.WEBINY_ENV)\n });\n\n const inlinePolicies = Promise.all([aws.getCallerIdentity({})]).then(([callerIdentity]) => [\n {\n name: \"dynamodb-policy\",\n policy: JSON.stringify({\n Version: \"2012-10-17\",\n Statement: [\n {\n Sid: \"PermissionForDynamodb\",\n Effect: \"Allow\",\n Action: [\"dynamodb:GetItem\"],\n Resource: [\n `arn:aws:dynamodb:${region}:${callerIdentity.accountId}:table/${dynamoDbTable}`,\n `arn:aws:dynamodb:${region}:${callerIdentity.accountId}:table/${dynamoDbTable}/*`\n ]\n }\n ]\n })\n }\n ]);\n\n const role = new aws.iam.Role(\n `${name}-role`,\n {\n inlinePolicies,\n managedPolicyArns: [aws.iam.ManagedPolicies.AWSLambdaBasicExecutionRole],\n assumeRolePolicy: {\n Version: \"2012-10-17\",\n Statement: [\n {\n Action: \"sts:AssumeRole\",\n Principal: aws.iam.Principals.LambdaPrincipal,\n Effect: \"Allow\"\n },\n {\n Action: \"sts:AssumeRole\",\n Principal: aws.iam.Principals.EdgeLambdaPrincipal,\n Effect: \"Allow\"\n }\n ]\n }\n },\n { parent: this }\n );\n\n // Some resources _must_ be put in us-east-1, such as Lambda at Edge.\n const awsUsEast1 = new aws.Provider(\"us-east-1\", { region: \"us-east-1\" });\n\n this.originRequest = new aws.lambda.Function(\n `${name}-origin-request`,\n {\n publish: true,\n runtime: \"nodejs14.x\",\n handler: \"index.handler\",\n role: role.arn,\n timeout: 5,\n memorySize: 128,\n code: createFunctionArchive({ region, dynamoDbTable })\n },\n { provider: awsUsEast1, parent: this }\n );\n\n this.registerOutputs();\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["request.js"],"names":["DocumentClient","require","DB_TABLE_NAME","DB_TABLE_REGION","documentClient","convertEmptyValues","region","exports","handler","event","request","Records","cf","requestedDomain","headers","host","value","originDomain","origin","custom","domainName","params","TableName","Key","PK","SK","Item","get","promise","from","uri","endsWith","tenant","console","log"],"mappings":";;AAAA,MAAM;AAAEA,EAAAA;AAAF,IAAqBC,OAAO,CAAC,0BAAD,CAAlC;;AAEA,MAAMC,aAAa,GAAG,iBAAtB;AACA,MAAMC,eAAe,GAAG,mBAAxB;AAEA,MAAMC,cAAc,GAAG,IAAIJ,cAAJ,CAAmB;AACtCK,EAAAA,kBAAkB,EAAE,IADkB;AAEtCC,EAAAA,MAAM,EAAEH;AAF8B,CAAnB,CAAvB;;AAKAI,OAAO,CAACC,OAAR,GAAkB,MAAMC,KAAN,IAAe;AAC7B,QAAMC,OAAO,GAAGD,KAAK,CAACE,OAAN,CAAc,CAAd,EAAiBC,EAAjB,CAAoBF,OAApC,CAD6B,CAE7B;;AAEA,QAAMG,eAAe,GAAGH,OAAO,CAACI,OAAR,CAAgBC,IAAhB,CAAqB,CAArB,EAAwBC,KAAhD;AACA,QAAMC,YAAY,GAAGP,OAAO,CAACQ,MAAR,CAAeC,MAAf,CAAsBC,UAA3C,CAL6B,CAO7B;;AACA,QAAMC,MAAM,GAAG;AACXC,IAAAA,SAAS,EAAEpB,aADA;AAEXqB,IAAAA,GAAG,EAAE;AACDC,MAAAA,EAAE,EAAG,UAASX,eAAgB,EAD7B;AAEDY,MAAAA,EAAE,EAAE;AAFH;AAFM,GAAf;AAQA,QAAM;AAAEC,IAAAA;AAAF,MAAW,MAAMtB,cAAc,CAACuB,GAAf,CAAmBN,MAAnB,EAA2BO,OAA3B,EAAvB;;AAEA,MAAIF,IAAJ,EAAU;AACN,UAAMG,IAAI,GAAGnB,OAAO,CAACoB,GAAR,CAAYC,QAAZ,CAAqB,GAArB,IAA4BrB,OAAO,CAACoB,GAApC,GAA0CpB,OAAO,CAACoB,GAAR,GAAc,GAArE;AACApB,IAAAA,OAAO,CAACoB,GAAR,GAAe,IAAGJ,IAAI,CAACM,MAAO,GAAEH,IAAK,EAArC;AAEAI,IAAAA,OAAO,CAACC,GAAR,CAAa,2BAA0BL,IAAK,SAAQnB,OAAO,CAACoB,GAAI,GAAhE;AACH,GALD,MAKO;AACHG,IAAAA,OAAO,CAACC,GAAR,CAAa,uCAAsCrB,eAAgB,GAAnE;AACH,GAzB4B,CA0B7B;;;AACAH,EAAAA,OAAO,CAACI,OAAR,CAAgBC,IAAhB,CAAqB,CAArB,EAAwBC,KAAxB,GAAgCC,YAAhC;AAEA,SAAOP,OAAP;AACH,CA9BD","sourcesContent":["const { DocumentClient } = require(\"aws-sdk/clients/dynamodb\");\n\nconst DB_TABLE_NAME = \"{DB_TABLE_NAME}\";\nconst DB_TABLE_REGION = \"{DB_TABLE_REGION}\";\n\nconst documentClient = new DocumentClient({\n convertEmptyValues: true,\n region: DB_TABLE_REGION\n});\n\nexports.handler = async event => {\n const request = event.Records[0].cf.request;\n // console.log(JSON.stringify(event.Records[0].cf, null, 2));\n\n const requestedDomain = request.headers.host[0].value;\n const originDomain = request.origin.custom.domainName;\n\n // Find tenant by domain\n const params = {\n TableName: DB_TABLE_NAME,\n Key: {\n PK: `DOMAIN#${requestedDomain}`,\n SK: \"A\"\n }\n };\n\n const { Item } = await documentClient.get(params).promise();\n\n if (Item) {\n const from = request.uri.endsWith(\"/\") ? request.uri : request.uri + \"/\";\n request.uri = `/${Item.tenant}${from}`;\n\n console.log(`Rewriting request from \"${from}\" to \"${request.uri}\"`);\n } else {\n console.log(`Failed to find a tenant for domain \"${requestedDomain}\"`);\n }\n // Restore the Host header\n request.headers.host[0].value = originDomain;\n\n return request;\n};\n"]}
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA","sourcesContent":["export { WebsiteTenantRouter } from \"./components/tenantRouter/WebsiteTenantRouter\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/pulumi-aws",
3
- "version": "5.24.0",
3
+ "version": "5.25.0-beta.0",
4
4
  "main": "index.ts",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "@pulumi/aws": "^4.10.0",
18
18
  "@pulumi/pulumi": "< 3.18.0",
19
- "@webiny/cli-plugin-deploy-pulumi": "5.24.0"
19
+ "@webiny/cli-plugin-deploy-pulumi": "5.25.0-beta.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@babel/cli": "^7.16.0",
@@ -24,11 +24,11 @@
24
24
  "@babel/preset-env": "^7.16.4",
25
25
  "@babel/preset-typescript": "^7.16.0",
26
26
  "@babel/runtime": "^7.16.3",
27
- "@webiny/cli": "^5.24.0",
28
- "@webiny/project-utils": "^5.24.0",
27
+ "@webiny/cli": "^5.25.0-beta.0",
28
+ "@webiny/project-utils": "^5.25.0-beta.0",
29
29
  "rimraf": "^3.0.2",
30
30
  "ttypescript": "^1.5.12",
31
- "typescript": "^4.1.3"
31
+ "typescript": "4.5.5"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "yarn webiny run build",
@@ -42,5 +42,5 @@
42
42
  ]
43
43
  }
44
44
  },
45
- "gitHead": "be0cbfcaa9247c658c44179af7943cc5d6d71bc7"
45
+ "gitHead": "2d3e7833575e88fde77d84e5490e746933a5ec28"
46
46
  }