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

signQuery results in error: Cannot set properties of undefined (setting 'X-Amz-Security-Token') #1763

Open
frtelg opened this issue Oct 16, 2024 · 2 comments

Comments

@frtelg
Copy link

frtelg commented Oct 16, 2024

I am using the aws4-axios interceptor to be able to call cache invalidation in API Gateway from a lambda. I have the following configuration:

    const interceptor = aws4Interceptor({
        options: {
            signQuery: true, // Use query string signing to avoid clash with the Authorization header
            region: process.env.AWS_REGION,
            service: 'execute-api',
        },
    });

As stated in the comment in the code snippet, I need to use signedQuery in order to be able to make the signed call, because the API Gateway call has a required Authorization header. When I do this however, I get the following error:
Cannot set properties of undefined (setting 'X-Amz-Security-Token').

Did I miss anything in my config or is this a bug maybe?

@frtelg
Copy link
Author

frtelg commented Oct 16, 2024

I'm expecting this to be a bug, as I'm able to work around this with the following:

        await this.axios.get(url, {
            ...config,
            headers: {
                'Cache-Control': 'max-age=0',
                ...config?.headers,
            },
            params: {
                ...config?.params,
                'X-Amz-Date': '',
                'X-Amz-Algorithm': '',
                'X-Amz-Credential': '',
                'X-Amz-SignedHeaders': '',
                'X-Amz-Signature': '',
            },
        });

Edit: better workaround:
Setting a default params property in your axios config:

axios.create({
        params: {
            // Params MUST be present for the interceptor to work
        },
    })

@frtelg
Copy link
Author

frtelg commented Oct 16, 2024

It can be fixed by changing this:

      for (const [key, value] of signedUrl.searchParams.entries()) {
        config.params[key] = value;
      }

To this:

    config.params = {
        ...config.params,
        ...Object.fromEntries(signedUrl.searchParams.entries())
     }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant