The docs talk about how to share an S3 bucket across stacks but I cant seem to get it to work for DynamoDB Tables? There doesnt seem to be any "export" method.
Does this not work Universally? Is there a work-around (maybe cdk.Output)?
It's just a missing feature in the DynamoDB library.
As for a workaround, where do you plan to consume this imported table? You could technically use cdk.Output and cdk.FnImportValue to export the tableName from stack A and import it into stack B, but if your consumption point expects a dynamodb.Table, then you won't be able to convert your imported name into a construct. If you only need a name at the consumption point, then you should be fine.
@eladb okay cool, thanks thats what I suspected. No worries ill work around it as you mention above.
Let鈥檚 keep this open until we implement this feature
Oh apologies 馃憤 BTW im sure you are aware but UserPoolResource, UserPoolClientResource and IdentityPoolResource are all missing export too 馃槃
Yes, we are planning a more rigorous process to align our APIs :-)
@eladb suppose im trying to export a table's Arn from one stack eg:
this.myTableArnOutput = new cdk.Output(this, "EventStoreTableArn", {
value: eventStoreTable.tableArn
});
I then want to use that Arn in a Role Policy in a different stack (in the same app):
myFunction.addToRolePolicy(
new PolicyStatement()
.addAction("dynamodb:Scan")
.addResource(props.myTableArnOutput.makeImportValue())
);
But I cant because makeImportValue() doesnt return the actual Arn only an import statement.
Do you have any suggestions here?
makeImportValue returns an token that resolves only at deploy-time, but since the value you are importing will eventually be a string (ARN), you can use makeImportValue().toString() to "stringify" the token so it can be "plugged in" anywhere strings go (in your case addResource(s)).
@eladb oh cool, neat trick thanks, ill give that a shot tomorrow 馃槃
Exports are actually transparent now, as long as your stacks are in the same app.
Closing.
Any ETA on a release :) ?
@ranguard sorry for the delay. We will be able to publish a release next week.
@eladb wonderful - thank you - I am looking forward to it :)
The new DynamoEventSource for Lambda expects a dynamodb.Table parameter. Is there some way to construct it from a table that is outside of the current stack? Or is there some alternative way to setup a DynamoEventSource?
Looking at the source code here, maybe DynamoEventSource could just allow configuring the tableStreamArn manually (instead of specifying a Table) in cases like this? https://github.com/awslabs/aws-cdk/blob/master/packages/%40aws-cdk/aws-lambda-event-sources/lib/dynamodb.ts#L36
Meanwhile I used this as a workaround to do the same thing as DynamoEventSource:
new lambda.EventSourceMapping(this, 'DynamoDBEvent', {
target: lambdaFunction,
batchSize: 100,
eventSourceArn: props.tableStreamArn,
startingPosition: lambda.StartingPosition.Latest,
})
lambdaFunction.addToRolePolicy(new iam.PolicyStatement()
.addAction('dynamodb:ListStreams')
.addResource('*')
)
lambdaFunction.addToRolePolicy(new iam.PolicyStatement()
.addActions('dynamodb:DescribeStream', 'dynamodb:GetRecords', 'dynamodb:GetShardIterator')
.addResource(props.tableStreamArn)
)
Most helpful comment
The new DynamoEventSource for Lambda expects a dynamodb.Table parameter. Is there some way to construct it from a table that is outside of the current stack? Or is there some alternative way to setup a DynamoEventSource?