Search code examples
aws-appsync

Accessing external file in aws appsync template mapper


Currently, we are using a json file which as a lambda layer. Is it possible to access this lambda layer in appsync template? There will be alot of field in this json file. It is something like this:


module.exports = {
    "INVALID_RFC": {"code": "111", "message": "RFC Code is invalid"}
}

I want to access this INVALID_RFC property from appsync template.


Solution

  • No, it is not possible for AppSync mapping templates.

    I ran into a similar problem. My workaround is

    • Use placeholders in a mapping template, for example. $INVALID_RFC$
    • Write a simple script (NodeJS, Python, or bash) that copies original Velocity templates over a build directory, and also replaces the placeholders with actual values. It's done easily with regular expressions
    • Deploy built mapping templates into AWS