-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Punchcard user onboarding #103
Comments
Hey! Thanks so much for helping to improve Punchcard. You're totally right about the on-boarding documentation - it has not received the attention it requires. I appreciate having a use-case to fulfill as a way of ensuring a great developer experience. I'll do my best to answer your questions and provide features where things are missing - have already derived a punch of work items from this issue that I'll treat as a high priority.
You'd currently have to "drop down" to the CDK layer to define indexes. It was possible once upon a time to do this in Punchcard but the rapid change eroded that feature. Tracking a Punchcard feature for this here: #104 For now, you could map into the const table = new DynamoDB.Table(..); // punchcard DDB table
table.resource.map(table => {
// now in the Build context, table is an @aws-cdk/aws-dynamodb.Table resource
table.addGlobalSecondaryIndex(..);
}); The worst part of this experience will be when you want to depend on it, as you'll have to manually assign environment variables and IAM permissions by implementing export interface Dependency<D> {
install: Build<Install>;
bootstrap: Run<Bootstrap<D>>;
}
const myGsiDependency: Dependency<any> = {
install: table.resource.map(table => (namespace, grantable) => {
// at build-time, set up the runtime environment with information needed to use the index
namespace.set('tableName', table.tableName);
namespace.set('indexName', ...);
table.grantReadData(grantable); // does this grant access to the index?
}),
bootstrap: Run.of(async (namespace, cache) => {
// at runtime, use the namespace and cache to initialize the client
const indexName = namespace.get('indexName');
return new MyIndexClient(indexName);
})
} I wonder if we could simplify this mapping process? Maybe some combinators or builders that construct the above implementation? Tracking: #106
Do you mean polymorphic tables where you store different record types in the same table that use the same key structure? I think this would require a union type in Punchcard (tracking here: #105): class A extends Record({
key: string,
type: string,
// specific to A
count: number
}) {}
class B extends Record({
key: string,
type: string,
// specific to B
label: string,
}) {}
const table = new DynamoDB.Table(stack, 'id', union(A, B), 'key') A workaround would be to use class A extends Record({
key: string,
variableData: any
}) {} For expressions, you can cast the any field to a type and still gain the benefit of the type-safe DSLs: await table.update('key', _ => [
_.variableData.as(string).set('type-safe string value'),
]);
I briefly showed how to do this with the DynamoDB example above. Punchcard wraps all the CDK stuff in a lazily evaluated export interface Resource<R> {
resource: Build<R>;
} I need to add substantial documentation to improve the understandability of this concept. Sorry about the on-boarding pain caused by this ... |
First off, the delight is all mine! Especially knowing how famous and untouchable you are about to become : ) Aight, let’s get into it. Thanx about the ‘dropping down to CDK’ guide. It deserves to be in the docs. But since I don’t know what exactly Build context means there, I have these extra questions:
On to manually implementing dependencies.
Yessir! Union types should work perfectly here. |
Yes, the CDK is synchronous, but
When you call If you're interested, it was inspired by the IO Monad - see: A gentle introduction to Haskell: IO and Scala's Cats Effect IO Previous discussions go into deeper detail: #54 and #53
Can you provide an example? AFAIK, I'm not doing anything to influence that.
This isn't specific to the CDK. Punchcard is currently tightly coupled to webpack and it might be a problem - when you synth your app, Punchcard runs webpack for you to create a small bundle and S3 asset which the CDK then deploys to AWS Lambda. #100 is tracking an idea to de-couple Punchcard from webpack and leave it up to developers. Developers would be free to use tools like Seems like this is what you're advocating for? Some questions:
|
In the upcoming version (v0.13.0), you'll be able to do the following: See (#108) for details. class RestarauntData extends Record({
id: string,
byUserId: string,
status: string,
avgRating: number,
starCount: string
}) {}
const RestaurantTable = new DynamoDB.Table(stack, 'RestaurantTable', {
data: RestarauntData,
key: {
partition: 'id'
}
}, Build.of({
billingMode: dynamodb.BillingMode.PAY_PER_REQUST
}));
const groupByStarCount = RestaurantTable.globalIndex({
indexName: 'groupByStarCount',
key: {
partition: 'byUserId',
sort: 'avgRating'
}
});
const groupByOwner = RestaurantTable.globalIndex({
indexName: 'groupByOwner',
key: {
partition: 'id',
sort: 'avgRating'
}
});
const groupByStatus = RestaurantTable.globalIndex({
indexName: 'groupByStatus',
key: {
partition: 'status',
sort: 'avgRating'
}
}); |
Doing some traveling these days. I'll get back to you asap. |
Enjoy your travels! :) |
Hello hello!
But the output looks the same as if there was just one lambda: Which makes me think that the same bundle is pushed for every lambda, correct? I’m quite wary of how lambda size influences cold starts. Some lambdas might have big-ass dependencies like image-processing or browser rendering packages, which we expect to be running slowly. But then there are the lean API-layer lambdas, which do not depend on those big packages, and should run and respond as fast as possible. Thanx for adding the Dynamo features! As you might see, I'm trying to get comfortable with the build process before I focus on the Punchcard API. Thanx! |
Sorry, been really busy with a hard problem. I'm trying to build a DSL for Step Functions and API Gateway and it's been really challenging.
Yes, this is the static part of the application. It is what is created in memory by requiring/importing the application's index file. It should instantiate the whole tree with Executing the application then becomes either:
Check out how This is the root of a
Yeah I have a problem with it. Webpack is an Ok workaround but it's far from ideal. By merging infrastructure and runtime code, it forces your runtime archive to include some build-time archives. I want a better solution but I'm not sure what to do at this time. 1-2 MB is OK for an archive size, but the worse problem I've encountered is where the memory usage is double (unable to support 128MB functions) when deploying with Some ideas:
I tried with I'd love it if someone who knew more about bundling could experiment and see how small the archive can get while maintaining good stack traces for logging.
I totally agree :) |
Oh, and congrats on the move to Lisbon! :) Thanks again for providing such useful feedback! Sorry that I sometimes take a while to respond, I need to do better at that. |
Absolutely nothing to worry about. I’m delighted to have my little part in your process here. Thanx a ton for your explication! I really hope you grab the attention of somebody with the relevant expertise. FWIW, I started getting familiar with CDK, so at least I’ll be able to follow the upcoming discussions :} Thanx! |
I'm starting to migrate a little Serverless app that I have to Punchcard, and report my experience along the way. It's a small app, and based on how it goes, I'll be doing the same for a different one that I have in production with a shitload of resources.
Some of the things I notice might just require better documentation, some might end up being feature requests. Whatever it ends up being, I'd just love to find a way to make this tool be my base infrastructure builder.
I'm starting here with a couple of things I noticed about dynamo with Punchcard's API.
I'm trying to migrate this table:
The text was updated successfully, but these errors were encountered: