amplify-backend
amplify-backend copied to clipboard
function env vars to cast to unknown, then expected type
Problem
TBD -- some project configurations are causing generated files to get picked up on typecheck and subsequently fail due to a clash with the node.js ProcessEnv type
.amplify/generated/env/pre-token-generation.ts(2,20): error TS2352: Conversion of type 'ProcessEnv' to type 'LambdaProvidedEnvVars & AmplifyBackendEnvVars' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type 'ProcessEnv' is missing the following properties from type 'LambdaProvidedEnvVars': _HANDLER, _X_AMZN_TRACE_ID, AWS_DEFAULT_REGION, AWS_REGION, and 20 more.
TypeScript validation check failed.
Resolution: Fix the syntax and type errors in your backend definition.
Issue number, if available:
Changes
changes function env generation's type casting from
as LambdaProcessEnv & Something
to
as unknown as LambdaProcessEnv & Something
though this could be revised to
type LambdaProcessEnv = {
// ... things
}
interface AmplifyFunctionProcessEnv extends NodeJS.ProcessEnv, LambdaProcessEnv {
// ... amplify backend vars
}
export const env = process.env as AmplifyFunctionProcessEnv
or something like
// This file is auto-generated by Amplify. Edits will be overwritten.
/** Lambda runtime environment variables
* @see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime
*/
interface LambdaProcessEnv extends NodeJS.ProcessEnv {
/** The handler location configured on the function. */
_HANDLER: string
/** The X-Ray tracing header. This environment variable changes with each invocation. */
_X_AMZN_TRACE_ID: string
/** The default AWS Region where the Lambda function is executed. */
AWS_DEFAULT_REGION: string
/** The AWS Region where the Lambda function is executed. If defined, this value overrides the AWS_DEFAULT_REGION. */
AWS_REGION: string
/** The runtime identifier, prefixed by AWS_Lambda_ (for example, AWS_Lambda_java8). */
AWS_EXECUTION_ENV: string
/** The name of the function. */
AWS_LAMBDA_FUNCTION_NAME: string
/** The amount of memory available to the function in MB. */
AWS_LAMBDA_FUNCTION_MEMORY_SIZE: string
/** The version of the function being executed. */
AWS_LAMBDA_FUNCTION_VERSION: string
/** The initialization type of the function, which is on-demand, provisioned-concurrency, or snap-start. */
AWS_LAMBDA_INITIALIZATION_TYPE: string
/** The name of the Amazon CloudWatch Logs group for the function. */
AWS_LAMBDA_LOG_GROUP_NAME: string
/** The name of the Amazon CloudWatch Logs stream for the function. */
AWS_LAMBDA_LOG_STREAM_NAME: string
/** AWS access key. */
AWS_ACCESS_KEY: string
/** AWS access key ID. */
AWS_ACCESS_KEY_ID: string
/** AWS secret access key. */
AWS_SECRET_ACCESS_KEY: string
/** AWS Session token. */
AWS_SESSION_TOKEN: string
/** The host and port of the runtime API. */
AWS_LAMBDA_RUNTIME_API: string
/** The path to your Lambda function code. */
LAMBDA_TASK_ROOT: string
/** The path to runtime libraries. */
LAMBDA_RUNTIME_DIR: string
/** The system library path. */
LD_LIBRARY_PATH: string
/** For X-Ray tracing, Lambda sets this to LOG_ERROR to avoid throwing runtime errors from the X-Ray SDK. */
AWS_XRAY_CONTEXT_MISSING: string
/** For X-Ray tracing, the IP address and port of the X-Ray daemon. */
AWS_XRAY_DAEMON_ADDRESS: string
}
interface AmplifyFunctionProcessEnv extends LambdaProcessEnv {
// ... amplify function env vars
}
export const env = process.env as AmplifyFunctionProcessEnv
Corresponding docs PR, if applicable:
Validation
Checklist
- [ ] If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
- [ ] If this PR requires a change to the Project Architecture README, I have included that update in this PR.
- [ ] If this PR requires a docs update, I have linked to that docs PR above.
- [ ] If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the
run-e2elabel set.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
🦋 Changeset detected
Latest commit: 231f3ac4a3eb0965f71e6e51fed806c51264bfbb
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| @aws-amplify/backend-function | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR