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 addEnvironment for custom function #2474

Open
ykethan opened this issue Jan 31, 2025 · 0 comments
Open

add addEnvironment for custom function #2474

ykethan opened this issue Jan 31, 2025 · 0 comments
Labels
feature-request New feature or request function Issue pertaining to Amplify Function good first issue Good for newcomers

Comments

@ykethan
Copy link
Member

ykethan commented Jan 31, 2025

Environment information

System:
  OS: macOS 15.2
  CPU: (8) arm64 Apple M1
  Memory: 172.80 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.18.1 - ~/.nvm/versions/node/v20.18.1/bin/node
  Yarn: 1.22.22 - /opt/homebrew/bin/yarn
  npm: 10.8.2 - ~/.nvm/versions/node/v20.18.1/bin/npm
  pnpm: 9.15.2 - ~/Library/pnpm/pnpm
NPM Packages:
  @aws-amplify/auth-construct: 1.6.0
  @aws-amplify/backend: 1.14.0
  @aws-amplify/backend-auth: 1.5.0
  @aws-amplify/backend-cli: 1.4.8
  @aws-amplify/backend-data: 1.4.0
  @aws-amplify/backend-deployer: 1.1.15
  @aws-amplify/backend-function: 1.12.1
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.4
  @aws-amplify/backend-secret: 1.1.5
  @aws-amplify/backend-storage: 1.2.4
  @aws-amplify/cli-core: 1.2.3
  @aws-amplify/client-config: 1.5.5
  @aws-amplify/deployed-backend-client: 1.5.0
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.12
  @aws-amplify/platform-core: 1.6.0
  @aws-amplify/plugin-types: 1.8.0
  @aws-amplify/sandbox: 1.2.10
  @aws-amplify/schema-generator: 1.2.7
  aws-amplify: 6.12.1
  aws-cdk: 2.176.0
  aws-cdk-lib: 2.176.0
  typescript: 5.7.3
No AWS environment variables
No CDK environment variables

Describe the feature

currently to add environment variables such as GraphQL API endpoint you need to access the environment property using

const env = {
  variables: {
    APPSYNC_API_ENDPOINT: backend.data.graphqlUrl,
  },
};
backend.customAPIFunction.resources.cfnResources.cfnFunction.environment = env;

but adding this would override any env variables directly set on the function, to add the GraphQL url or reference other resources you need to override the property

// backend.ts
const cfnFn = backend.customAPIFunction.resources.cfnResources.cfnFunction;

cfnFn.addPropertyOverride("Environment.Variables", {
  // @ts-expect-error
  ...((cfnFn.environment?.variables || {}) as Record<string, string>),
  KEY3: "value3", // Add new vars
  KEY4: "value4",
});


Use case

keep existing environment variables present on the custom function created in the defineFunction and extend them using addEnvironment on backend.customAPIFunction.addEnvironment

@ykethan ykethan added the pending-triage Incoming issues that need categorization label Jan 31, 2025
@ykethan ykethan changed the title addEnvironment on custom function add addEnvironment for custom function Jan 31, 2025
@josefaidt josefaidt added feature-request New feature or request function Issue pertaining to Amplify Function and removed pending-triage Incoming issues that need categorization labels Jan 31, 2025
@ykethan ykethan added the good first issue Good for newcomers label Jan 31, 2025
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 function Issue pertaining to Amplify Function good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants