Code Monkey home page Code Monkey logo

Comments (13)

mhart avatar mhart commented on July 16, 2024

Not sure – not all that familiar with axios. Have you been able to do it successfully using the builtin Node.js https library as described in the README?

from aws4.

mhart avatar mhart commented on July 16, 2024

Btw, url is not a standard property that the Node.js http module accepts. See here for accepted values:

https://nodejs.org/api/http.html#http_http_request_options_callback

from aws4.

jeremyburton avatar jeremyburton commented on July 16, 2024

Thanks for your very quick response. I've just tried the following and I'm getting the same error.

let request = {
  host: 'xxxxxx.execute-api.eu-west-2.amazonaws.com/dev',
  method: 'GET',
  path: '/xxxxxx',
  service: 'execute-api',
  region: 'eu-west-2'
}
let signedRequest = aws4.sign(request, {
  accessKeyId: rootState.auth.accessKeyId,
  secretAccessKey: rootState.auth.secretAccessKey,
  sessionToken: rootState.auth.sessionToken
})
console.log(signedRequest)
https.request(signedRequest, function (res) { res.pipe(process.stdout) }).end()

Console error:
"Failed to load https://xxxxxxx.execute-api.eu-west-2.amazonaws.com/dev/xxxxxx: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 403. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."

x-amzn-errortype: InvalidSignatureException

from aws4.

jeremyburton avatar jeremyburton commented on July 16, 2024

By the way, I'm using the following in my webpack config as you recommended elsewhere. Don't know if that has any significance here?

resolve: {
      alias: {
        querystring: 'querystring-browser'
      }
    }

from aws4.

mhart avatar mhart commented on July 16, 2024

That host doesn't look correct?

from aws4.

mhart avatar mhart commented on July 16, 2024

Also, I'm guessing you're trying to do this from the browser? Sorry, that wasn't clear in your initial issue. Try just getting it working from Node itself first – then you can tell if it's just the way you're using the browser, or something more deep seeded.

from aws4.

jeremyburton avatar jeremyburton commented on July 16, 2024

Yes, I'm trying from the browser. I'm building an SPA with Vue - there is no Node server.

Can you tell me what looks wrong with host? Axios doesn't require a host to be specified. Is this a requirement of aws4 or of Node.js https module?

Thanks for your help with this. I really appreciate it. I'm stuck for any alternative solution for AWS v4 signature.

from aws4.

mhart avatar mhart commented on July 16, 2024

Your host has a path in it – /dev at the end there.

Please read up on the options here:

https://nodejs.org/api/http.html#http_http_request_options_callback

from aws4.

jeremyburton avatar jeremyburton commented on July 16, 2024

Success! As you suggested, fixing the host got this working with the https library. I will now try to get it working with axios and will post again here when I do.

Again, many thanks for your help.

from aws4.

mhart avatar mhart commented on July 16, 2024

No probs, glad you're getting somewhere! 👍

from aws4.

alexjfno1 avatar alexjfno1 commented on July 16, 2024

@jeremyburton Did you have any luck getting it working with Axios?

from aws4.

jeremyburton avatar jeremyburton commented on July 16, 2024

@alexjfno1 Yes, see this article for very useful guidance.

from aws4.

shiiyan avatar shiiyan commented on July 16, 2024

For someone who sees this, axios also works fine with aws4 just like https. If you see the error in the title, please double check your host url path region service attributes in your request options.

from aws4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.