Maciej Radzikowski Profile picture
Jun 1, 2022 β€’ 15 tweets β€’ 5 min read β€’ Read on X
AWS AppSync added new $utils to VTL.

Let's look at the new and existing AppSync $utils with 9 code examples!

A thread πŸ§΅πŸ‘‡
VTL, the Velocity Template Language, is used to build JSONs for AppSync Resolvers. VTL allows putting logic in the Resolvers' behavior.

$util provides a set of functions with rich capabilities to enhance this logic without utilizing additional Lambda functions.
Btw, VTL is not the easiest or most developer-friendly language.

But this RFC gives us hope for the JavaScript-based Resolvers in the future:
github.com/aws/aws-appsyn…
Now, to the point - $util functions in AppSync VTL πŸ‘‡
1️⃣ Debug logs - newly added (finally!)

AppSync writes logs to the CloudWatch depending on the log level set:
- ERROR: error logs only
- ALL: info and error logs
2️⃣ Generating IDs

$util.autoKsuid() is newly added, K-Sortable Unique IDentifier generator.

ULID and KSUID generate unique but sortable (by creation time) identifiers!

More about KSUID: github.com/segmentio/ksuid
3️⃣ Working with JSON

Serializing and deserializing objects to/from JSON is common with any Data Sources AppSync connects to.
4️⃣ Suppressing functions output

In VTL, Lists and Maps are Java objects.
You can use Java API to work with them.

Many Map and List methods return values that you don't want to include in the template output. Therefore, you need to discard or "suppress" them.
5️⃣ Throwing error
6️⃣ Validating data

$util.validate() function will throw an error if the condition is not fulfilled. No #if blocks are needed.
7️⃣ Default value fallback

Perfect for handling optional query arguments.
8️⃣ String conversions

Only the basics are available - uppercase, lowercase, and find and replace.

Btw, I understand that "toReplace" name was supposed to match "toUpper" and "toLower"...
9️⃣ Generating timestamps

Please use ISO 8601 wherever you can...
That's not all!

There are also helpers for working with Lists, Maps, DynamoDB, RDS, HTTP, and XML.

But this thread is long enough, so maybe next time? πŸ˜‰
If you found it useful:

1. Follow me @radzikowski_m for more like this
2. Please ❀️ and πŸ” the 1st tweet above to share

Thank you!

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Maciej Radzikowski

Maciej Radzikowski Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @radzikowski_m

Nov 23, 2022
I've passed 7 AWS Certification exams, all on the first attempt.

How? And WHY? 🀨

I gathered all my tips and tricks, including:
- which Cert to select?
- how to prepare?
- how to solve questions?
- how to pay only 50%?
and more.

A post and a thread πŸ‘‡
betterdev.blog/how-to-pass-aw…
I tweeted a guide after passing the DevOps Professional exam...
Read 12 tweets
Nov 2, 2022
This week I passed the AWS Architect Professional exam πŸŽ‰

Here are my hints on preparing, exam scope, understanding questions, and some pro tips!

A thread πŸ§΅πŸ‘‡ AWS Certified Solutions Arc...
πŸ§‘β€πŸŽ“ Learning

Video courses provide the best source of condensed knowledge for exams. My choice is always @StephaneMaarek courses on Udemy.
How to learn?

Don't make it just passive watching. Make notes, mind maps, whatever suits you.

Go to AWS Console and play with configurations yourself. You will remember much more this way.

I wrote more about how I take notes when I passed my DevOps exam:
Read 19 tweets
Sep 29, 2022
While I was vacationing 🌴, AWS Step Functions got new intrinsic functions. Let's check them out!
permanently delete
They added 14 new functions, making it 18 in total.

A thread πŸ§΅πŸ‘‡
(with code examples!) Image
❓ What are intrinsic functions?

➑️ Operations you can make on the states' payloads to convert/generate data directly in Step Functions, without using additional Task states and doing it in Lambda functions.

Intrinsic functions = less states = simpler (and cheaper) workflows
Read 19 tweets
Jul 11, 2022
Structuring a real-life serverless application

There are hundreds of tutorials on creating a Lambda function with API Gateway.

But there is much less about how to build real-life serverless applications with dozens of resources.

A post and a thread πŸ§΅πŸ‘‡
articles.alfa1.com/serverless-pro…
1️⃣ Monorepo

Splitting the application into multiple deployment units (like CloudFormation stacks) and being able to deploy them individually let us:

- (re)deploy faster
- reduce merge conflicts
- not worry about the CF resources count limit
A sample Store application can be a monorepo split into 5 stacks:
- UI
- Auth
- API
- Catalog
- Orders

When developing, initially, you have to deploy all the stacks to create your own development environment. But then you have to re-deploy only the one stack you work on πŸš€ Image
Read 12 tweets
Apr 12, 2022
A handy Decision Tree for choosing the right messaging service on AWS.

As per my calculations, following it gives you a 90% chance of making the right choice.

Read more in the thread πŸ§΅πŸ‘‡ Image
I did a summary and comparison of SQS, SNS, EventBridge, and Kinesis in a thread a while ago.
Now, this Decision Tree is an extension of it, helping make the decision.

But there is still this 10% chance it won't help you!
Read 6 tweets
Feb 9, 2022
AWS Step Functions overview

A thread πŸ§΅πŸ‘‡
(with images!)
1️⃣ What is AWS Step Functions?

Serverless, low-code service to build and visualize workflows orchestration.
But what does it mean?

- serverless - you pay only for the number of step transitions executed
- low-code - defined in JSON/YAML or visual builder
- workflows - multi-step processes
- orchestration - centralized coordination across multiple services
Read 19 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(