Skip to content
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

Add environment variables support for JS resolvers #267

Open
sashee opened this issue Feb 27, 2023 · 2 comments
Open

Add environment variables support for JS resolvers #267

sashee opened this issue Feb 27, 2023 · 2 comments
Labels
feature-request New feature or request

Comments

@sashee
Copy link

sashee commented Feb 27, 2023

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.

@onlybakam
Copy link
Contributor

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?

@sashee
Copy link
Author

sashee commented Mar 2, 2023

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.

@onlybakam onlybakam added the feature-request New feature or request label Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants