You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a script needs some information about other resources, the primary way is to use environment variables. For example, I have this Terraform script:
resource "aws_appsync_function" "Mutation_pairUsers_1" {
# ...
code = <<EOF
import {util} from "@aws-appsync/utils";
export function request(ctx) {
return {
version: "2018-05-29",
operation: "TransactWriteItems",
transactItems: [
{
// needs the table name here
table: "${aws_dynamodb_table.user.name}",
operation: "UpdateItem",
key: {
id : {S: ctx.args.user1}
},
// ...
},
{
// ...
}
]
}
}
// ...
EOF
}
The TransactWriteItems needs the table name which is part of the environment. Currently, the only choice is string concatenation or templating (table: "${aws_dynamodb_table.user.name}",) but there could be a separate block for these values that are available under the process.env, similarly to how Lambda functions work.
The text was updated successfully, but these errors were encountered:
hey @sashee , for somethinig like this, how would you want to define the env variables? would you want to do this as a configuration on the AppSync API, or on a specific resolver?
Hey @onlybakam , that's a great question and I haven't thought about it.
Probably adding it to individual resolvers gives the greatest flexibility and I don't see many use-cases when API-wide variables are better. When I need to inject something from the environment it is usually because of the Transact*Items DDB calls need the table names but even these are rare (maybe ~10% of all resolvers). So overall both would work.
When a script needs some information about other resources, the primary way is to use environment variables. For example, I have this Terraform script:
The
TransactWriteItems
needs the table name which is part of the environment. Currently, the only choice is string concatenation or templating (table: "${aws_dynamodb_table.user.name}",
) but there could be a separate block for these values that are available under theprocess.env
, similarly to how Lambda functions work.The text was updated successfully, but these errors were encountered: