aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.12k stars 578 forks source link

Error on sending `CreateInvalidationCommand` #5245

Closed pinarruiz closed 1 year ago

pinarruiz commented 1 year ago

Checkboxes for prior research

Describe the bug

I have the following code:

import {
  CloudFrontClient,
  CreateInvalidationCommand,
} from "@aws-sdk/client-cloudfront";

const cloudFront = new CloudFrontClient({});

export async function invalidateCFPaths(paths: string[]) {
  const invCom = new CreateInvalidationCommand({
    DistributionId: process.env.CLOUDFRONT_ID,
    InvalidationBatch: {
      CallerReference: `${Date.now()}`,
      Paths: {
        Quantity: paths.length,
        Items: paths,
      },
    },
  });

  return await cloudFront.send(invCom);
}

The code is an adapted copy of the example found at the docs: CreateInvalidationCommand.

With this I get this error:

Argument of type 'CreateInvalidationCommand' is not assignable to parameter of type 'Command<ServiceInputTypes, ServiceInputTypes, ServiceOutputTypes, ServiceOutputTypes, SmithyResolvedConfiguration<HttpHandlerOptions>>'.
  Property 'middlewareStack' is missing in type 'CreateInvalidationCommand' but required in type 'Command<ServiceInputTypes, ServiceInputTypes, ServiceOutputTypes, ServiceOutputTypes, SmithyResolvedConfiguration<HttpHandlerOptions>>'.ts(2345)

SDK version number

@aws-sdk/client-cloudfront@3.414.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v16.15.1

Reproduction Steps

Using @aws-sdk/client-cloudfront@3.414.0.

import {
  CloudFrontClient,
  CreateInvalidationCommand,
} from "@aws-sdk/client-cloudfront";

const cloudFront = new CloudFrontClient({});

export async function invalidateCFPaths(paths: string[]) {
  const invCom = new CreateInvalidationCommand({
    DistributionId: process.env.CLOUDFRONT_ID,
    InvalidationBatch: {
      CallerReference: `${Date.now()}`,
      Paths: {
        Quantity: paths.length,
        Items: paths,
      },
    },
  });

  return await cloudFront.send(invCom);
}

Observed Behavior

Argument of type 'CreateInvalidationCommand' is not assignable to parameter of type 'Command<ServiceInputTypes, ServiceInputTypes, ServiceOutputTypes, ServiceOutputTypes, SmithyResolvedConfiguration<HttpHandlerOptions>>'.
  Property 'middlewareStack' is missing in type 'CreateInvalidationCommand' but required in type 'Command<ServiceInputTypes, ServiceInputTypes, ServiceOutputTypes, ServiceOutputTypes, SmithyResolvedConfiguration<HttpHandlerOptions>>'.ts(2345)

Expected Behavior

The invalidation gets done.

Possible Solution

No response

Additional Information/Context

This same code is working on version: 3.410.0 and it stopped working when upgraded package to version 3.414.0.

The code is an adapted copy of the example found at the docs: CreateInvalidationCommand.

RanVaknin commented 1 year ago

Hi @pinarruiz ,

What version of typescript are you running?

I'm able to run CreateInvalidation successfully:

import { CloudFrontClient, CreateInvalidationCommand } from "@aws-sdk/client-cloudfront"; 

const client = new CloudFrontClient("us-east-1");

async function run(){
    try {
        const res= await client.send(new CreateInvalidationCommand({
            DistributionId: "REDACTED",
            InvalidationBatch: {
                CallerReference: `${Date.now()}`,
                Paths: {
                    Quantity: 1,
                    Items: ["/"]
                },
            },
        }))
        console.log(res)
    } catch (error) {
        console.log(error)
    }    
}
run()
$ npm list 
4042-cloudfront-invalidatecache@1.0.0 /Users/rvaknin/test_folder/4042-cloudfront-invalidatecache
├── @aws-sdk/client-cloudfront@3.414.0

$ tsc --version
Version 5.0.4

Thanks, Ran~

pinarruiz commented 1 year ago

Hey @RanVaknin,

I am using version 5.2.2.

Thanks ;) Alex

RanVaknin commented 1 year ago

Hi @pinarruiz ,

Is this a new project you are starting or did you start seeing this after upgrading? The error "Property 'middlewareStack' is missing in type 'CreateInvalidationCommand' but required in type 'Command... " might be related to us moving some packages from '@aws-sdk/' to '@smithy/'.

Please try deleting your node_modules and package-lock.json and then running npm install.

If that doesn't work can you please share your tsconfig file here and the contents of npm ls ?

Thanks, Ran~

pinarruiz commented 1 year ago

Hi @RanVaknin

Is this a new project you are starting or did you start seeing this after upgrading?

It is an upgrade, its a nextjs project and this function runs on an api route, the error is thrown on build time (And also in the editor itself).

Please try deleting your node_modules and package-lock.json and then running npm install.

Just done that (using yarn tho), and noticed that there was a new version of the package (3.418.0), my issue is solved. Just for the sake of it I tried using 3.414.0, while removing node_modules and the yarn.lock and it worked too.

I am closing the issue on this comment. Thanks for everything. :smile:

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.