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

WriteGetObjectResponse - 405 MethodNotAllowed: The specified method is not allowed against this resource. #3675

Closed
3 tasks done
micheleriso opened this issue Mar 24, 2021 · 3 comments
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@micheleriso
Copy link

micheleriso commented Mar 24, 2021

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
When using the WriteGetObjectResponse method, I get the following error MethodNotAllowed: The specified method is not allowed against this resource.

Is the issue in the browser/Node.js?
Node.js

If on Node.js, are you running this on AWS Lambda?
Yes

Details of the browser/Node.js version
Lambda Node Runtime 14.x

SDK version number
v2.870.0

To Reproduce (observed behavior)

const AWS = require('aws-sdk');
const s3 = new AWS.S3();

exports.handler = async (event, context) => {

  const objectContext = event['getObjectContext']
  const RequestRoute = objectContext['outputRoute']
  const RequestToken = objectContext['outputToken']

  try {
    const res = await s3.writeGetObjectResponse({
      RequestRoute,
      RequestToken,
      Body: "TEST",
      StatusCode: 200

    }).promise()

    console.log("Write Get Object SUCCESS", res)
  } catch (e) {
    console.error("WRITE GET OBJECT FAILED", e)
  }

  return {
    statusCode: 200
  }
};

Expected behavior
It should return TEST however it throws

2021-03-24T12:15:46.042Z	df108614-2c61-46a6-87a4-965e5fcbed95	ERROR	WRITE GET OBJECT FAILED MethodNotAllowed: The specified method is not allowed against this resource.
    at Request.extractError (/var/task/node_modules/aws-sdk/lib/services/s3.js:712:35)
    at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:688:14)
    at Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /var/task/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:690:12)
    at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
  code: 'MethodNotAllowed',
  region: null,
  time: 2021-03-24T12:15:46.041Z,
  requestId: 'RQKY7099ES64PZRZ',
  extendedRequestId: '2LO2pWksxx8RNSsko7VL299wDuA65uGsOZH6SaHpCDvBWRDmw+x1khsJYZ2ZPGU5lXvY/R2Jt4g=',
  cfId: undefined,
  statusCode: 405,
  retryable: false,
  retryDelay: 3.0760893896501385
}

@micheleriso micheleriso added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 24, 2021
@micheleriso
Copy link
Author

There is a workaround that can be used to temporary fix this issue

/** START Workaround for bug #3675 **/
const s3 = new AWS.S3({ region: "us-east-1", endpoint: "s3-object-lambda.us-east-1.amazonaws.com" });
s3.__proto__.api.endpointPrefix = "s3-object-lambda";
/** END Workaround for bug #3675 **/

I've documented the usage in my medium blog if that can help

@joe-keane
Copy link

joe-keane commented Mar 31, 2021

Thanks for your sample @micheleriso, it was quite helpful.
Meanwhile, I notice this issue was fixed in 2.876.0.
I got a sample running and no workaround required.

@micheleriso
Copy link
Author

Thanks Joe, it now works perfectly. I've updated my article to reflect that.

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. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants