@@ -130,67 +130,6 @@ function getDynamoDBArn(tableName) {
130
130
} ;
131
131
}
132
132
133
- function getDynamoDBIndexArn ( tableName , indexName ) {
134
- if ( isIntrinsic ( tableName ) ) {
135
- // most likely we'll see a { Ref: LogicalId }, which we need to map to
136
- // { Fn::GetAtt: [ LogicalId, Arn ] } to get the ARN
137
- if ( tableName . Ref ) {
138
- return {
139
- 'Fn::Join' : [
140
- '/' ,
141
- [
142
- { 'Fn::GetAtt' : [ tableName . Ref , 'Arn' ] } ,
143
- 'index' ,
144
- indexName ,
145
- ] ,
146
- ] ,
147
- } ;
148
- }
149
- // but also support importing the table name from an external stack that exports it
150
- // as we still want to support direct state machine actions interacting with those tables
151
- if ( tableName [ 'Fn::ImportValue' ] ) {
152
- return {
153
- 'Fn::Join' : [
154
- ':' ,
155
- [
156
- 'arn' ,
157
- { Ref : 'AWS::Partition' } ,
158
- 'dynamodb' ,
159
- { Ref : 'AWS::Region' } ,
160
- { Ref : 'AWS::AccountId' } ,
161
- {
162
- 'Fn::Join' : [
163
- '/' ,
164
- [
165
- 'table' ,
166
- tableName ,
167
- 'index' ,
168
- indexName ,
169
- ] ,
170
- ] ,
171
- } ,
172
- ] ,
173
- ] ,
174
- } ;
175
- }
176
- }
177
-
178
- return {
179
- 'Fn::Join' : [
180
- ':' ,
181
- [
182
- 'arn' ,
183
- { Ref : 'AWS::Partition' } ,
184
- 'dynamodb' ,
185
- { Ref : 'AWS::Region' } ,
186
- { Ref : 'AWS::AccountId' } ,
187
- `table/${ tableName } /index/${ indexName } ` ,
188
- ] ,
189
- ] ,
190
- } ;
191
- }
192
-
193
-
194
133
function getBatchPermissions ( ) {
195
134
return [ {
196
135
action : 'batch:SubmitJob,batch:DescribeJobs,batch:TerminateJob' ,
@@ -243,26 +182,31 @@ function getEcsPermissions() {
243
182
}
244
183
245
184
function getDynamoDBPermissions ( action , state ) {
246
- const indexName = state . Parameters [ 'IndexName.$' ]
247
- ? '*'
248
- : state . Parameters . IndexName ;
249
-
250
185
let resource ;
251
- if ( indexName ) {
252
- resource = state . Parameters [ 'TableName.$' ]
186
+
187
+ if ( state . Parameters [ 'TableName.$' ] ) {
188
+ // When the TableName is only known at runtime, we
189
+ // have to provide * permissions during deployment.
190
+ resource = '*' ;
191
+ } else if ( state . Parameters [ 'IndexName.$' ] || state . Parameters . IndexName ) {
192
+ // When the Parameters contain an IndexName, we have to build a
193
+ // longer arn that includes the index.
194
+ const indexName = state . Parameters [ 'IndexName.$' ]
195
+ // We must provide * here instead of state.Parameters['IndexName.$'], because we don't know
196
+ // which index will be targeted when we the step function runs
253
197
? '*'
254
- : getDynamoDBIndexArn ( state . Parameters . TableName , indexName ) ;
198
+ : state . Parameters . IndexName ;
199
+
200
+ resource = getDynamoDBArn ( `${ state . Parameters . TableName } /index/${ indexName } ` ) ;
255
201
} else {
256
- resource = state . Parameters [ 'TableName.$' ]
257
- ? '*'
258
- : getDynamoDBArn ( state . Parameters . TableName ) ;
202
+ resource = getDynamoDBArn ( state . Parameters . TableName ) ;
259
203
}
204
+
260
205
return [ {
261
206
action,
262
207
resource,
263
208
} ] ;
264
209
}
265
-
266
210
function getRedshiftDataPermissions ( action , state ) {
267
211
if ( [ 'redshift-data:ExecuteStatement' , 'redshift-data:BatchExecuteStatement' ] . includes ( action ) ) {
268
212
const clusterName = _ . has ( state , 'Parameters.ClusterIdentifier' ) ? state . Parameters . ClusterIdentifier : '*' ;
0 commit comments