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

error when serverless uses aws-sdk/client-cloudformation #6779

Open
4 tasks done
mlopez34 opened this issue Jan 7, 2025 · 22 comments
Open
4 tasks done

error when serverless uses aws-sdk/client-cloudformation #6779

mlopez34 opened this issue Jan 7, 2025 · 22 comments
Assignees
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. p1 This is a high priority issue potential-regression Marking this issue as a potential regression to be checked by team member response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.

Comments

@mlopez34
Copy link

mlopez34 commented Jan 7, 2025

Checkboxes for prior research

Describe the bug

have recently gotten this error:

....
/usr/local/lib/node_modules/serverless/node_modules/@aws-sdk/client-cloudformation/dist-cjs/index.js:343
  static {
         ^

SyntaxError: Unexpected token '{'
    at wrapSafe (internal/modules/cjs/loader.js:1029:16)
    .....

When using serverless to deploy to AWS using github actions
9 hours ago from this post github action successfully deployed, i noticed first failure 4 hours ago and all since then.
noticed that the latest update for client-cloudformation on npm was 7 hours ago so it is most likely this latest update.

currently using the following on github actions:

Have not tested upgrading to Node v20, but that is probably not the solution since I ran locally successfully, and i have node v18.20.2, serverless 3.38.0, npm 10.9.1

Can provide more info if needed
Thanks

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

Node v 18.20.5 [email protected] npm: 10.8.2

Reproduction Steps

Ubuntu v 24.04.1
Node v 18.20.5
[email protected]
npm: 10.8.2

Observed Behavior

on github actions, when deploying using serverless which uses this package @aws-sdk/client-cloudformation, the deployment fails since latest update

Expected Behavior

successful deployment

Possible Solution

No response

Additional Information/Context

No response

@mlopez34 mlopez34 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 7, 2025
@github-actions github-actions bot added the potential-regression Marking this issue as a potential regression to be checked by team member label Jan 7, 2025
@TippuTraya
Copy link

When this will be resolved.

@bragboy
Copy link

bragboy commented Jan 7, 2025

Happening the same for me.

ubuntu-22.04

@ChristianH108
Copy link

same for me

1 similar comment
@jniravel
Copy link

jniravel commented Jan 7, 2025

same for me

@osheppardap
Copy link

Happening here, as well. Seeing it in an AWS Codebuild "aws/codebuild/amazonlinux2-x86_64-standard:4.0" environment, using serverless version 3.35.2

@ChristianH108
Copy link

ChristianH108 commented Jan 7, 2025

2025/01/07 17:55:29.302923 Running command serverless deploy --config ${ServerlessFileName} --stage ${Environment}
--
233 | /usr/local/lib/node_modules/serverless/node_modules/@aws-sdk/client-cloudformation/dist-cjs/index.js:343
234 | static {
235 | ^
236 |  
237 | SyntaxError: Unexpected token '{'
238 | at wrapSafe (internal/modules/cjs/loader.js:1029:16)
239 | at Module._compile (internal/modules/cjs/loader.js:1078:27)
240 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
241 | at Module.load (internal/modules/cjs/loader.js:979:32)
242 | at Function.Module._load (internal/modules/cjs/loader.js:819:12)
243 | at Module.require (internal/modules/cjs/loader.js:1003:19)
244 | at require (internal/modules/cjs/helpers.js:107:18)
245 | at Object.<anonymous> (/usr/local/lib/node_modules/serverless/node_modules/@serverless/dashboard-plugin/lib/monitoring/monitoring-integration-service.js:10:5)
246 | at Module._compile (internal/modules/cjs/loader.js:1114:14)
247 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
248 | at Module.load (internal/modules/cjs/loader.js:979:32)
249 | at Function.Module._load (internal/modules/cjs/loader.js:819:12)
250 | at Module.require (internal/modules/cjs/loader.js:1003:19)
251 | at require (internal/modules/cjs/helpers.js:107:18)
252 | at Object.<anonymous> (/usr/local/lib/node_modules/serverless/node_modules/@serverless/dashboard-plugin/lib/plugin.js:26:38)
253 | at Module._compile (internal/modules/cjs/loader.js:1114:14)
254 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
255 | at Module.load (internal/modules/cjs/loader.js:979:32)
256 | at Function.Module._load (internal/modules/cjs/loader.js:819:12)
257 | at Module.require (internal/modules/cjs/loader.js:1003:19)
258 | at require (internal/modules/cjs/helpers.js:107:18)
259 | at Object.<anonymous> (/usr/local/lib/node_modules/serverless/node_modules/@serverless/dashboard-plugin/index.js:5:18)
260 | at Module._compile (internal/modules/cjs/loader.js:1114:14)
261 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
262 | at Module.load (internal/modules/cjs/loader.js:979:32)
263 | at Function.Module._load (internal/modules/cjs/loader.js:819:12)
264 | at Module.require (internal/modules/cjs/loader.js:1003:19)
265 | at require (internal/modules/cjs/helpers.js:107:18)
266 | at Object.<anonymous> (/usr/local/lib/node_modules/serverless/lib/cli/handle-error.js:6:35)
267 | at Module._compile (internal/modules/cjs/loader.js:1114:14)
268 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
269 | at Module.load (internal/modules/cjs/loader.js:979:32)
270 | at Function.Module._load (internal/modules/cjs/loader.js:819:12)
271 | at Module.require (internal/modules/cjs/loader.js:1003:19)
272 | at require (internal/modules/cjs/helpers.js:107:18)
273 | at Object.<anonymous> (/usr/local/lib/node_modules/serverless/scripts/serverless.js:17:21)
274 | at Module._compile (internal/modules/cjs/loader.js:1114:14)
275 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
276 | at Module.load (internal/modules/cjs/loader.js:979:32)
277 | at Function.Module._load (internal/modules/cjs/loader.js:819:12)
278 | at Module.require (internal/modules/cjs/loader.js:1003:19)
279 | at require (internal/modules/cjs/helpers.js:107:18)
280 | at /usr/local/lib/node_modules/serverless/bin/serverless.js:73:7

@aBurmeseDev aBurmeseDev self-assigned this Jan 7, 2025
@aBurmeseDev aBurmeseDev added investigating Issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 7, 2025
@kuhe
Copy link
Contributor

kuhe commented Jan 7, 2025

The syntax is a static initialization block that was introduced in Node.js 16.11.0, according to
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks

This SDK recently updated to require Node.js 18 and higher announced in #6252. The EOL date of Node.js 16 was in September 2023.

Is the execution environment using a lower Node.js version?

@aBurmeseDev
Copy link
Member

While we're looking into it, could someone share minimal reproducible code along with your Github action?

cc: @mlopez34 @ChristianH108 @bragboy

@aBurmeseDev aBurmeseDev added the p1 This is a high priority issue label Jan 7, 2025
@jperocho
Copy link

jperocho commented Jan 8, 2025

For a temporary working solution, explicitly add the working versions of the following packages to the package.json dependencies. I chose version 3.714.0.

Here is my list, but you can simply add "@aws-sdk/client-cloudformation": "3.714.0". In my case, I need to add all the following packages listed below for it to work.

...
  "dependencies": {
    "@aws-sdk/client-dynamodb": "3.714.0",
    "@aws-sdk/client-s3": "3.714.0",
    "@aws-sdk/client-ses": "3.714.0",
    "@aws-sdk/lib-dynamodb": "3.714.0",
    "@aws-sdk/s3-presigned-post": "3.714.0",
    "@aws-sdk/s3-request-presigner": "3.714.0",
    "@aws-sdk/util-dynamodb": "3.714.0",
    "@aws-sdk/client-cloudformation": "3.714.0",
    "@aws-sdk/credential-provider-env": "3.714.0",
    "@aws-sdk/credential-provider-ini": "3.714.0",
    "@aws-sdk/credential-provider-node": "3.714.0",
    "@aws-sdk/client-acm": "3.714.0",
    "@aws-sdk/core": "3.714.0",
    "@aws-sdk/types": "3.714.0",
    "@aws-sdk/client-sts": "3.714.0",
    "@aws-sdk/util-endpoints": "3.714.0",
    "@aws-sdk/client-sso-oidc": "3.714.0",
    "@aws-sdk/middleware-logger": "3.714.0",
    "@aws-sdk/util-user-agent-node": "3.714.0",
    "@aws-sdk/middleware-user-agent": "3.714.0",
    "@aws-sdk/middleware-host-header": "3.714.0",
    "@aws-sdk/region-config-resolver": "3.714.0",
    "@aws-sdk/middleware-recursion-detection": "3.714.0",
    "@aws-sdk/credential-provider-sso": "3.714.0",
    "@aws-sdk/credential-provider-http": "3.714.0",
    "@aws-sdk/credential-provider-process": "3.714.0",
    "@aws-sdk/credential-provider-web-identity": "3.714.0",
    "@aws-sdk/client-sso": "3.714.0",
    "@aws-sdk/token-providers": "3.714.0",
    "@aws-sdk/middleware-endpoint-discovery": "3.714.0",
    "@aws-sdk/middleware-ssec": "3.714.0",
    "@aws-sdk/middleware-sdk-s3": "3.714.0",
    "@aws-sdk/signature-v4-multi-region": "3.714.0",
    "@aws-sdk/middleware-bucket-endpoint": "3.714.0",
    "@aws-sdk/middleware-expect-continue": "3.714.0",
    "@aws-sdk/middleware-flexible-checksums": "3.714.0",
    "@aws-sdk/middleware-location-constraint": "3.714.0",
    "@aws-sdk/util-format-url": "3.714.0",
    "@aws-sdk/client-iam": "3.714.0",
    "@aws-sdk/client-lambda": "3.714.0",
    "@aws-sdk/client-api-gateway": "3.714.0",
    "@aws-sdk/client-eventbridge": "3.714.0",
    "@aws-sdk/client-cognito-identity-provider": "3.714.0",
    "@aws-sdk/middleware-sdk-api-gateway": "3.714.0",
    "@aws-sdk/client-route-53": "3.714.0",
    "@aws-sdk/client-apigatewayv2": "3.714.0",
    "@aws-sdk/credential-providers": "3.714.0",
    "@aws-sdk/middleware-sdk-route53": "3.714.0",
    "@aws-sdk/client-cognito-identity": "3.714.0",
    "@aws-sdk/credential-provider-cognito-identity": "3.714.0",
    ...
    ```

@mlopez34
Copy link
Author

mlopez34 commented Jan 8, 2025

For a temporary working solution, explicitly add the working versions of the following packages to the package.json dependencies. I chose version 3.714.0.

Here is my list, but you can simply add "@aws-sdk/client-cloudformation": "3.714.0". In my case, I need to add all the following packages listed below for it to work.

@jperocho this doesn't work because serverless is the one that makes use of @aws-sdk/client-cloudformation": "3.714.0 not my project itself, so adding it to my project's package.json doesn't really do anything, serverless overrides it.

@mlopez34
Copy link
Author

mlopez34 commented Jan 8, 2025

While we're looking into it, could someone share minimal reproducible code along with your Github action?

cc: @mlopez34 @ChristianH108 @bragboy

name: deployment

on:
  workflow_dispatch:
    
  push:
    branches: [ "master" ]
  # pull_request:
  #   branches: [ "**" ]

jobs:
  build:

    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./v2Api
  
    strategy:
      matrix:
        node-version: [18.x]

    steps:
    - uses: actions/checkout@v3

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
        cache-dependency-path: './v2Api/package-lock.json'
    - run: npm ci --omit=dev
    - run: npm run build --if-present
    - name: serverless deploy
      uses: serverless/github-action@v3
      with:
        args: -c "cd ./v2Api/scripts && ./deploy.sh"
        entrypoint: /bin/sh
      env:
        # SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
        # my other env vars

this is the github action used, the failure happens on the serverless deploy section, and you can probably use any boilerplate serverless.yml file

@aBurmeseDev
Copy link
Member

aBurmeseDev commented Jan 8, 2025

@mlopez34 thanks for sharing the GitHub action used.
I wanted to share an update with some findings for everyone. I created a GitHub action for the purpose of reproducing this issue, keeping it minimal and avoiding unnecessary dependencies.

Minimal Repro with cloudformation

name: Create CloudFormation Stack

on:
  workflow_dispatch:

jobs:

  create-stack:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: ['>=16.11.0', '18.20.5', '20.18.1', '<16.11.0']

    steps:
    - name: Print version details
      run: |
        echo "Ubuntu version:"
        lsb_release -a
        echo "-----------------"

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}     

    - name: Print Node.js version
      run: node --version

    - name: Print npm version
      run: npm --version
      
    - name: Print AWS SDK version
      run: |
        npm install @aws-sdk/client-cloudformation
        node -e 'console.log(require("@aws-sdk/client-cloudformation/package.json").version)'

    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v2
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-west-2

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}

    - name: Create CloudFormation Stack
      run: |
        npm install @aws-sdk/client-cloudformation
        node -e 'require("@aws-sdk/client-cloudformation")'
        NODE_VERSION="${{ matrix.node-version }}"
        STACK_NAME="my-stack-node-$(echo "$NODE_VERSION" | sed 's/[^a-zA-Z0-9-]/-/g' | sed 's/^-//' | sed 's/-$//')"
        aws cloudformation create-stack \
          --stack-name "$STACK_NAME" \
          --template-body '{"Resources": {"MyBucket": {"Type": "AWS::S3::Bucket", "Properties": {"BucketName": "sdk-node-repro"}}}}' \
          --capabilities CAPABILITY_NAMED_IAM
      env:
        AWS_REGION: us-west-2

The workflow installs the @aws-sdk/client-cloudformation package, configures AWS credentials, and creates a CloudFormation stack with a single S3 bucket resource. It tests different Node.js versions: ['>=16.11.0', '18.20.5', '20.18.1', '<16.11.0'], and pins the AWS SDK version to v3.723.0. You can check out all the versions used in the provided workflow links below.

Test Case Scenarios

Case 1

  • Node versions: >=16.11.0 <16.11.0 18.20.5
  • SDK version: 3.723.0
  • Ubuntu 22.04.5 LTS
  • ✅ >=16.11.0 18.20.5 ❌ v16.10.0
    Workflow run: link

Case 2

  • Node versions: >=16.11.0 18.20.5 20.18.1 22.13.0
  • SDK version: 3.723.0
  • Ubuntu 22.04.5 LTS
  • ✅ >=16.11.0 18.20.5 20.18.1 22.13.0
    Workflow run: link

Case 3

  • Node versions: 16.10.0 >=16.11.0 18.20.5 20.18.1
  • SDK version: 3.723.0
  • Ubuntu 22.04.5 LTS
  • ✅ >=16.11.0 18.20.5 20.18.1 ❌ v16.10.0
    Workflow run: link

The finding is that the reported error is reproducible only with <16.11.0 or v16.10.0. The rest of the Node.js versions completed the workflow run successfully. Another finding since you mentioned the failure happens on serverless deploy section is that I didn't have serverless in my minimal repro.

@aBurmeseDev aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed investigating Issue is being investigated and/or work is in progress to resolve the issue. labels Jan 8, 2025
@mlopez34
Copy link
Author

mlopez34 commented Jan 8, 2025

tried using node 20.x on the github workflow, it uses node v20.18.1
same result

@JosueFS
Copy link

JosueFS commented Jan 8, 2025

same here, im using @datadog/datadog-ci as dependency.

@vishal2develop
Copy link

As a temporary solution, We locked down our serverless framework version in jenkins to 3.25.
Nodejs Version = 16.9.0

@ChristianH108
Copy link

we're using node.js 14 and 3.38 - is this going to work again?

@Celebrate-Reinhard
Copy link

As pointed out here by Adesin-fr serverless/[email protected] does not have the error anymore.

@mlopez34
Copy link
Author

mlopez34 commented Jan 8, 2025

This works now by using serverless/[email protected]

thanks

@aBurmeseDev
Copy link
Member

@Celebrate-Reinhard @mlopez34 - thanks for sharing your finding and the solution here.

For everyone else, the root cause to this issue appears to be serverless/github-action@v3, solution is to use serverless/[email protected].

From linked issue above:

serverless/github-action@v3 uses an old version of Node, BUT, serverless/[email protected] uses a more recent version

Since the root cause isn't SDK related issue, we'll be closing this soon. Let us know if issue persists with suggested solution.

@aBurmeseDev aBurmeseDev added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 8, 2025
@MrSpark2591
Copy link

we're using node.js 14 and 3.38 - is this going to work again?

We are also using the same and the error persists.

@ChristianH108
Copy link

we changed our deployment to use node.js 18 and serverless framework 3.38.0 - using different images in AWS that have that version of node.js installed and all works again

@ChristianH108
Copy link

standard 7 image for codedeploy in AWS works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. p1 This is a high priority issue potential-regression Marking this issue as a potential regression to be checked by team member response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
Projects
None yet
Development

No branches or pull requests