| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,8 @@ export const __dynamoDBDefaults = { | |||
| 25 | 25 | export const dynamoTable = (tableConfig?: { | |
| 26 | 26 | tableName?: string, | |
| 27 | 27 | environmentKey?: string, | |
| 28 | - nativeConfig?: any | ||
| 28 | + nativeConfig?: any, | ||
| 29 | + exists?: boolean | ||
| 29 | 30 | }) => (target: Function) => { | |
| 30 | 31 | let tableDefinitions = getMetadata(CLASS_DYNAMOTABLECONFIGURATIONKEY, target) || []; | |
| 31 | 32 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,8 @@ export const s3Storage = (s3Config?: { | |||
| 12 | 12 | eventSourceConfiguration?: { | |
| 13 | 13 | Event?: any, | |
| 14 | 14 | Filter?: any | |
| 15 | - } | ||
| 15 | + }, | ||
| 16 | + exists?: boolean | ||
| 16 | 17 | }) => (target: Function) => { | |
| 17 | 18 | let s3Definitions = getMetadata(CLASS_S3CONFIGURATIONKEY, target) || []; | |
| 18 | 19 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,8 +127,9 @@ export class DynamoTable extends Api { | |||
| 127 | 127 | const tableName = ({ TableName: tableConfig.tableName, ...tableConfig.nativeConfig }).TableName | |
| 128 | 128 | ||
| 129 | 129 | const calcTableName = tableConfig.environmentKey && process.env[tableConfig.environmentKey] ? process.env[tableConfig.environmentKey] : '' | |
| 130 | + const suffix = tableConfig.exists ? '' : `-${process.env.FUNCTIONAL_STAGE}` | ||
| 130 | 131 | const initParams = { | |
| 131 | - TableName: (calcTableName || tableName) + `-${process.env.FUNCTIONAL_STAGE}` | ||
| 132 | + TableName: (calcTableName || tableName) + suffix | ||
| 132 | 133 | } | |
| 133 | 134 | ||
| 134 | 135 | return { ...initParams, ...params } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,8 +88,9 @@ export class S3Storage extends Api { | |||
| 88 | 88 | const bucketName = bucketConfig.bucketName | |
| 89 | 89 | ||
| 90 | 90 | const calcBucketName = bucketConfig.environmentKey && process.env[bucketConfig.environmentKey] ? process.env[bucketConfig.environmentKey] : '' | |
| 91 | + const suffix = bucketConfig.exists ? '' : `-${process.env.FUNCTIONAL_STAGE}` | ||
| 91 | 92 | const initParams = { | |
| 92 | - Bucket: (calcBucketName || bucketName) + `-${process.env.FUNCTIONAL_STAGE}` | ||
| 93 | + Bucket: (calcBucketName || bucketName) + suffix | ||
| 93 | 94 | } | |
| 94 | 95 | ||
| 95 | 96 | return { ...initParams, ...params } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,9 +25,15 @@ export const tableResources = ExecuteStep.register('DynamoDB-Tables', async (con | |||
| 25 | 25 | export const tableResource = async (context) => { | |
| 26 | 26 | const { tableConfig } = context | |
| 27 | 27 | ||
| 28 | + tableConfig.AWSTableName = tableConfig.tableName | ||
| 29 | + | ||
| 30 | + if (tableConfig.exists) return | ||
| 31 | + | ||
| 32 | + tableConfig.AWSTableName = `${tableConfig.tableName}-${context.stage}` | ||
| 33 | + | ||
| 28 | 34 | const properties = { | |
| 29 | 35 | ...__dynamoDBDefaults, | |
| 30 | - TableName: `${tableConfig.tableName}-${context.stage}`, | ||
| 36 | + TableName: tableConfig.AWSTableName, | ||
| 31 | 37 | ...tableConfig.nativeConfig | |
| 32 | 38 | }; | |
| 33 | 39 | ||
@@ -55,7 +61,6 @@ export const tableResource = async (context) => { | |||
| 55 | 61 | sourceStackName: DYNAMODB_TABLE_STACK | |
| 56 | 62 | }) | |
| 57 | 63 | ||
| 58 | - tableConfig.tableName = properties.TableName | ||
| 59 | 64 | tableConfig.resourceName = resourceName | |
| 60 | 65 | ||
| 61 | 66 | } | |
@@ -75,6 +80,8 @@ export const tableSubscribers = ExecuteStep.register('DynamoDB-Table-Subscriptio | |||
| 75 | 80 | ||
| 76 | 81 | export const tableSubscriber = async (context) => { | |
| 77 | 82 | const { tableConfig, subscriber } = context | |
| 83 | + | ||
| 84 | + if (tableConfig.exists) return | ||
| 78 | 85 | ||
| 79 | 86 | const properties = { | |
| 80 | 87 | "BatchSize": 1, | |
@@ -115,6 +122,8 @@ export const tableSubscriber = async (context) => { | |||
| 115 | 122 | ||
| 116 | 123 | export const dynamoStreamingPolicy = async (context) => { | |
| 117 | 124 | const { tableConfig, serviceDefinition } = context | |
| 125 | + | ||
| 126 | + if (tableConfig.exists) return | ||
| 118 | 127 | ||
| 119 | 128 | let policy = serviceDefinition.roleResource.Properties.Policies.find(p => p.PolicyDocument.Statement[0].Action.includes('dynamodb:GetRecords')) | |
| 120 | 129 | if (!policy) { | |
@@ -149,6 +158,6 @@ export const dynamoStreamingPolicy = async (context) => { | |||
| 149 | 158 | } | |
| 150 | 159 | ||
| 151 | 160 | policy.PolicyDocument.Statement[0].Resource.push({ | |
| 152 | - "Fn::Sub": "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/" + tableConfig.tableName + "/stream/*" | ||
| 161 | + "Fn::Sub": "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/" + tableConfig.AWSTableName + "/stream/*" | ||
| 153 | 162 | }) | |
| 154 | 163 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -227,7 +227,7 @@ export const dynamoPolicy = async (context) => { | |||
| 227 | 227 | ], | |
| 228 | 228 | "Resource": usedTableConfigs.map(t => { | |
| 229 | 229 | return { | |
| 230 | - "Fn::Sub": "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/" + t.tableName | ||
| 230 | + "Fn::Sub": "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/" + t.AWSTableName | ||
| 231 | 231 | } | |
| 232 | 232 | }) | |
| 233 | 233 | }] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,36 +56,41 @@ export const s3Storages = ExecuteStep.register('S3-Storages', async (context) => | |||
| 56 | 56 | }) | |
| 57 | 57 | ||
| 58 | 58 | for (const s3Config of configs) { | |
| 59 | - const s3BucketDefinition = await executor({ | ||
| 59 | + await executor({ | ||
| 60 | 60 | context: { ...context, s3Config }, | |
| 61 | 61 | name: `S3-Storage-${s3Config.bucketName}`, | |
| 62 | 62 | method: s3Storage | |
| 63 | 63 | }) | |
| 64 | - | ||
| 65 | - await executor({ | ||
| 66 | - context: { ...context, s3Config, s3BucketDefinition }, | ||
| 67 | - name: `S3-Storage-Subscription-${s3Config.bucketName}`, | ||
| 68 | - method: s3StorageSubscriptions | ||
| 69 | - }) | ||
| 70 | 64 | } | |
| 71 | 65 | }) | |
| 72 | 66 | ||
| 73 | 67 | export const s3Storage = async (context) => { | |
| 74 | 68 | const { s3Config } = context | |
| 75 | 69 | ||
| 76 | - const s3Properties = { | ||
| 77 | - "BucketName": `${s3Config.bucketName}-${context.stage}` | ||
| 78 | - } | ||
| 70 | + s3Config.AWSBucketName = s3Config.bucketName | ||
| 79 | 71 | ||
| 80 | - const s3Bucket = { | ||
| 81 | - "Type": "AWS::S3::Bucket", | ||
| 82 | - "Properties": s3Properties | ||
| 83 | - } | ||
| 72 | + if (!s3Config.exists) { | ||
| 73 | + s3Config.AWSBucketName = `${s3Config.bucketName}-${context.stage}` | ||
| 74 | + | ||
| 75 | + const s3Properties = { | ||
| 76 | + "BucketName": s3Config.AWSBucketName | ||
| 77 | + } | ||
| 84 | 78 | ||
| 85 | - const resourceName = `S3${s3Config.bucketName}` | ||
| 86 | - const bucketResourceName = setResource(context, resourceName, s3Bucket, S3_STORAGE_STACK) | ||
| 87 | - s3Config.resourceName = bucketResourceName | ||
| 79 | + const s3Bucket = { | ||
| 80 | + "Type": "AWS::S3::Bucket", | ||
| 81 | + "Properties": s3Properties | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + const resourceName = `S3${s3Config.bucketName}` | ||
| 85 | + const bucketResourceName = setResource(context, resourceName, s3Bucket, S3_STORAGE_STACK) | ||
| 86 | + s3Config.resourceName = bucketResourceName | ||
| 88 | 87 | ||
| 88 | + await executor({ | ||
| 89 | + context: { ...context, s3BucketDefinition: s3Bucket }, | ||
| 90 | + name: `S3-Storage-Subscription-${s3Config.bucketName}`, | ||
| 91 | + method: s3StorageSubscriptions | ||
| 92 | + }) | ||
| 93 | + } | ||
| 89 | 94 | ||
| 90 | 95 | for (const { serviceDefinition, serviceConfig } of s3Config.services) { | |
| 91 | 96 | if (!serviceConfig.injected) continue | |
@@ -96,8 +101,6 @@ export const s3Storage = async (context) => { | |||
| 96 | 101 | method: s3StoragePolicy | |
| 97 | 102 | }) | |
| 98 | 103 | } | |
| 99 | - | ||
| 100 | - return s3Bucket | ||
| 101 | 104 | } | |
| 102 | 105 | ||
| 103 | 106 | ||
@@ -142,7 +145,7 @@ export const s3StoragePolicy = async (context) => { | |||
| 142 | 145 | "", | |
| 143 | 146 | [ | |
| 144 | 147 | "arn:aws:s3:::", | |
| 145 | - `${s3Config.bucketName}-${context.stage}`, | ||
| 148 | + `${s3Config.AWSBucketName}`, | ||
| 146 | 149 | "/*" | |
| 147 | 150 | ] | |
| 148 | 151 | ] | |
@@ -152,6 +155,8 @@ export const s3StoragePolicy = async (context) => { | |||
| 152 | 155 | export const s3StorageSubscriptions = async (context) => { | |
| 153 | 156 | const { s3Config } = context | |
| 154 | 157 | ||
| 158 | + if (s3Config.exists) return | ||
| 159 | + | ||
| 155 | 160 | for (const { serviceDefinition, serviceConfig } of s3Config.services) { | |
| 156 | 161 | if (!serviceConfig.eventSource) continue | |
| 157 | 162 | ||
@@ -171,6 +176,8 @@ export const s3StorageSubscriptions = async (context) => { | |||
| 171 | 176 | ||
| 172 | 177 | export const s3BucketSubscription = async (context) => { | |
| 173 | 178 | const { serviceDefinition, serviceConfig, s3Config, s3BucketDefinition } = context | |
| 179 | + | ||
| 180 | + if (s3Config.exists) return | ||
| 174 | 181 | ||
| 175 | 182 | await setStackParameter({ | |
| 176 | 183 | ...context, | |
@@ -204,6 +211,9 @@ export const s3BucketSubscription = async (context) => { | |||
| 204 | 211 | ||
| 205 | 212 | export const s3Permissions = (context) => { | |
| 206 | 213 | const { serviceDefinition, serviceConfig, s3Config, s3BucketDefinition } = context | |
| 214 | + | ||
| 215 | + if (s3Config.exists) return | ||
| 216 | + | ||
| 207 | 217 | const properties = { | |
| 208 | 218 | "FunctionName": { | |
| 209 | 219 | "Ref": serviceDefinition.resourceName | |
| Back | FazBrowse Home | New Git URL |
0 commit comments