amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Failed to override due to: VMError: Cannot find module 'fs'.

Open gouthasnm opened this issue 4 years ago • 3 comments

Before opening, please confirm:

  • [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

How did you install the Amplify CLI?

npm

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

14.18.3

Amplify CLI Version

8.3.1

What operating system are you using?

Amazon Linux

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

Ran amplify override api and then added the below code to override.ts

// This file is used to override the REST API resources configuration import { AmplifyApiRestResourceStackTemplate } from '@aws-amplify/cli-extensibility-helper'; import * as logs from '@aws-cdk/aws-logs';

export function override(resources: AmplifyApiRestResourceStackTemplate) { const logGroupName = "/aws/custom-access-logs/AccessLogs" const parts = logGroupName.split('/'); const id = parts[parts.length - 1];

const accessLogGroup = logs.LogGroup.fromLogGroupName(this, id, logGroupName)

resources.deploymentResource.stageDescription = { accessLogSetting: { destinationArn: accessLogGroup.logGroupArn, format: '$context.identity.sourceIp,$context.identity.caller,$context.identity.user,$context.requestTime,$context.httpMethod,$context.resourcePath,$context.protocol,$context.status,$context.responseLength,$context.requestId', } } }

Amplify Categories

api

Amplify Commands

override

Describe the bug

Amplify build fails with:

⠋ Building resource custom/DataStreamDataFiles⠋ Building custom resources🛑 Failed to override WebsiteAPIs due to: VMError: Cannot find module 'fs'.

Expected behavior

Build should succeed

Reproduction steps

  1. amplify override api
  2. make changes to override.ts
  3. amplify build

GraphQL schema(s)

No response

Project Identifier

No response

Log output

⠋ Building resource custom/DataStreamDataFiles⠋ Building custom resources🛑 Failed to override WebsiteAPIs due to: VMError: Cannot find module 'fs'.

Additional information

No response

gouthasnm avatar Sep 07 '22 20:09 gouthasnm

Hey @gouthasnm :wave: thanks for raising this! Marking this as a duplicate of https://github.com/aws-amplify/amplify-cli/issues/9063 and https://github.com/aws-amplify/amplify-cli/issues/10066, and unfortunately we currently do not support additional modules in overrides. Additional modules are supported in custom CDK resources, however

josefaidt avatar Sep 07 '22 21:09 josefaidt

Thanks @josefaidt , my intention is to add access logging. I have created log group via [custom CDK resources]. However, I want to add it to restApi using: resources.deploymentResource.stageDescription = { accessLogSetting: { destinationArn: accessLogGroup.logGroupArn, format: '$context.identity.sourceIp,$context.identity.caller,$context.identity.user,$context.requestTime,$context.httpMethod,$context.resourcePath,$context.protocol,$context.status,$context.responseLength,$context.requestId', } } }

Could you please advice if I should get restapi by name in custom resources and the enable Access logging there?

In general, what is the best way to enable access logging for rest api.

UPDATE: I believe my request is similar to https://github.com/aws-amplify/amplify-cli/issues/9821 . Does it mean that I cannot add Access logging using Custom Resource as well? Is the only option to do it via UI and potentially having to set it every time amplify push is done?

Thank You!

gouthasnm avatar Sep 07 '22 21:09 gouthasnm

@gouthasnm I had similar Problems with amplify overrides....

As far as i see, you finally would just need the arn of the log group?

You could build the arn of the log group manually by using the cloudformation join operations.

e.g. in my case i wanted to add the cognito user pool as authorizer in my restapi. Here is a snipped of my override code

image

Using "Fn:join" you could build your logGroupArn because the logGroupArns have always the same structure arn:aws:logs:awsRegion:awsAccountID:log-group:logGroupName:*

Stefan-WW avatar Sep 20 '22 06:09 Stefan-WW