aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 79 forks source link

API override error #109

Open nikname opened 2 years ago

nikname commented 2 years ago

Before opening, please confirm:

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v14.19.0

Amplify CLI Version

7.6.21

What operating system are you using?

Windows 10

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

Amplify Categories

api

Amplify Commands

override, push

Describe the bug

After editing the override.ts file (generated from amplify override api) to add a custom resolver when I try to push the changes I see the following error in the output

šŸ›‘ Error: Skipping override due to VMError: Cannot find module 'fs'

If I confirm the push operation I don't see my changes.

Expected behavior

See my changes

Reproduction steps

  1. amplify override api
  2. Edit the override.ts file as follow
    
    import { AmplifyApiGraphQlResourceStackTemplate } from "@aws-amplify/cli-extensibility-helper";
    import * as appsync from "@aws-cdk/aws-appsync";

export function override(resources: AmplifyApiGraphQlResourceStackTemplate) { const createGroupMessageResolver = new appsync.CfnResolver(resources.api.rootstack, "PromotePost", { apiId: resources.api.GraphQLAPI.attrApiId, fieldName: "promotePost", typeName: "Mutation", requestMappingTemplate: appsync.MappingTemplate.fromFile(${__dirname}/resolvers/Mutation.promotePost.req.vtl).renderTemplate(), responseMappingTemplate: appsync.MappingTemplate.fromFile(${__dirname}/resolvers/Mutation.promotePost.res.vtl).renderTemplate(), dataSourceName: "PostTable" }); }

3. `amplify push` 

### GraphQL schema(s)

<details>

```graphql
type Post @model {
  title: String
}

type Mutations {
  promotePost(): Post
}

Log output

``` # Put your logs below this line ā ™ Building resource api/myapiBe careful when using @auth directives on a field in a root type. @auth directives on field definitions use the source object to perform authorization logic and the source will be an empty object for fields on root types. Static group authorization should perform as expected. šŸ›‘ Error: Skipping override due to VMError: Cannot find module 'fs' āœ” Successfully pulled backend environment dev from the cloud. ā ™ Building resource api/myapiBe careful when using @auth directives on a field in a root type. @auth directives on field definitions use the source object to perform authorization logic and the source will be an empty object for fields on root types. Static group authorization should perform as expected. šŸ›‘ Error: Skipping override due to VMError: Cannot find module 'fs' ```

Additional information

No response

josefaidt commented 2 years ago

Hey @nikname :wave: thanks for raising this! I was able to successfully reproduce this behavior using the provided reproduction steps. Thank you for providing those details! The root cause here is similar to https://github.com/aws-amplify/amplify-cli/issues/9063, however I'll mark this as a non-duplicate bug due to the different workflow.

As mentioned in the docs, it should be possible to write our VTL templates in a separate file. As a workaround, please try defining the VTL templates as strings inside the overrides.ts file.

Marking as a bug šŸ™‚

josefaidt commented 2 years ago

Hey @nikname :wave: there was a bit of confusion on my part with this docs link I provided. Under the "VTL Resolvers" section it walks us through creating a custom CDK resource rather than _overriding` the GraphQL Resource. In a custom CDK resource these fs ops are permitted and we should be able to add VTL templates using the example you provided. Can you try those steps and see if that mitigates this issue?

MikeG96 commented 2 years ago

Hello, I have the same problem but trying override OpenDomainName, I have Windows 10

import {
  AmplifyApiGraphQlResourceStackTemplate,
  getProjectInfo,
} from "@aws-amplify/cli-extensibility-helper";

export function override(resources: AmplifyApiGraphQlResourceStackTemplate) {
  const { projectName, envName } = getProjectInfo();

  // Override OpenSearch Resource Configuration
  resources.opensearch.OpenSearchDomain.domainName = `${projectName}-op-${envName}`;
}
blanchma commented 2 years ago

Same issue overriding storage.

KeiSugiyasu commented 2 years ago

Similar issue overriding opensearch.OpenSearchStreamingLambdaFunction.

ā “ Building resource api/*** Your instance type for OpenSearch is t2.small.elasticsearch, you may experience performance issues or data loss. Consider reconfiguring with the instructions here https://docs.amplify.aws/cli/graphql/search-and-result-aggregations/#set-up-opensearch-for-production-environments
šŸ›‘ Error: Skipping override due to VMError: Cannot find module 'fs'

Overrides functionality is not implemented for this category
āœ” Successfully pulled backend environment *** from the cloud.
ā “ Building resource api/*** Your instance type for OpenSearch is t2.small.elasticsearch, you may experience performance issues or data loss. Consider reconfiguring with the instructions here https://docs.amplify.aws/cli/graphql/search-and-result-aggregations/#set-up-opensearch-for-production-environments
šŸ›‘ Error: Skipping override due to VMError: Cannot find module 'fs'