CORS issue with docker dynamodb-local












0














I am having issues with Cross-Origin access with a docker dynamodb-local container. I spin up the container, throw in some generated data, and in the script from the browser (using AWS sdk) connect to it locally. It is able to pull the first item (a general data entry) from a docClient.get(...). Then I browse to a different path, where a docClient.batchGet(...) is run, where the Cross-Origin Request Blocked error occurs. I cannot find out why.



I have -cors "*" set in the dynamodb-local, I did think that maybe my OS was blocking cors somehow, but I do not have NGINX or apache (or other) running/installed. No firewall running, nothing else on my Linux system that could interfere, I think. I am sure that docker itself does not care and lets the container worry about CORS. Issue persists and tested in Chromium and Firefox.



Steps:




  1. Spin up docker container,

  2. Add generated data to database

  3. Launch webpack dev-server (localhost:8080)

  4. Browse to localhost:8080, (docClient.get works, gets general-data)

  5. Browse to localhost:8080/test, (docClient.batchGet causes CORS error).


Docker:



clone of https://github.com/cnadiminti/docker-dynamodb-local



with docker-entry.sh changed to:



#!/user/bin/env bash
set -e

exec java -Djava.library.path=/var/dynamodb_local/ ${JAVA_OPTS} -jar /var/dynamodb_local/DynamoDBLocal.jar -part ${DYNAMODB_PORT} -cors "*" "$@"


which is spun up with docker run -d -p 8000:8000 --name dynamodb my-dynamodb.



Data is then generated and placed in the database.



In the browser (vue and webpack) (Fetcher.js):



import AWS from 'aws'

AWS.config.update({
region: 'ca-central-1',
accesssKeyId: 'local',
secretAccessKey: 'local',
endpoint: 'http://localhost:8000',
sslEnabled: false,
maxRetries: 5
})

const docClient = new AWS.DynamoDB.DocumentClient()

docClient.get({
Key: {
hash: 'general-info',
},
TableName: 'test'
}, (err, data) => {...})

docClient.batchGet({
RequestItems: {
'test': {
Keys: [...]
}
}
}, (err, data) => {...})


error:



Access to XMLHttpRequest at 'http://localhost:8000/' from origin 8080/test:1 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

POST http://localhost:8000/ 400 (Bad Request) aws-sdk.min.js:53

Error: Network Failure Fetcher.js:151
at XMLHttpRequest.<anonymous> (aws-sdk.min.js:53)









share|improve this question






















  • POST localhost:8000 400 (Bad Request) aws-sdk.min.js:53 ← So you don’t have a CORS problem. Instead you have a 400 Bad Request problem. The only reason you see mention of Access-Control-Allow-Origin in the error message is because servers don’t add application-configured response headers to 4xx error responses; they only add them to 2xx success responses. Anyway, the server is telling you that the request your code sent isn’t formatted in the way it expects.
    – sideshowbarker
    Nov 12 '18 at 22:02










  • @sideshowbarker, omg your right, it had nothing to do with CORS. The issue was in my batchGet I get the HASH key and RANGE key from a string by splitting it via the -, which is string HASH and a number RANGE, I just forgot to cast the Number(). I guess I saw the CORS and just could not let it go. Thank you, at least you helped me cut through my stupidity there.
    – Drew
    Nov 13 '18 at 3:53












  • Glad you got it resolved. Anyway, as far as how you initially interpreted the error, you’re not alone — the browser message for this case is misleading, and a common reaction is to take it as an indication that there’s some CORS misconfiguration. So that browser message would be less misleading and more helpful if it cited the status code of the response right at the beginning of the message rather than at the end…
    – sideshowbarker
    Nov 13 '18 at 7:18


















0














I am having issues with Cross-Origin access with a docker dynamodb-local container. I spin up the container, throw in some generated data, and in the script from the browser (using AWS sdk) connect to it locally. It is able to pull the first item (a general data entry) from a docClient.get(...). Then I browse to a different path, where a docClient.batchGet(...) is run, where the Cross-Origin Request Blocked error occurs. I cannot find out why.



I have -cors "*" set in the dynamodb-local, I did think that maybe my OS was blocking cors somehow, but I do not have NGINX or apache (or other) running/installed. No firewall running, nothing else on my Linux system that could interfere, I think. I am sure that docker itself does not care and lets the container worry about CORS. Issue persists and tested in Chromium and Firefox.



Steps:




  1. Spin up docker container,

  2. Add generated data to database

  3. Launch webpack dev-server (localhost:8080)

  4. Browse to localhost:8080, (docClient.get works, gets general-data)

  5. Browse to localhost:8080/test, (docClient.batchGet causes CORS error).


Docker:



clone of https://github.com/cnadiminti/docker-dynamodb-local



with docker-entry.sh changed to:



#!/user/bin/env bash
set -e

exec java -Djava.library.path=/var/dynamodb_local/ ${JAVA_OPTS} -jar /var/dynamodb_local/DynamoDBLocal.jar -part ${DYNAMODB_PORT} -cors "*" "$@"


which is spun up with docker run -d -p 8000:8000 --name dynamodb my-dynamodb.



Data is then generated and placed in the database.



In the browser (vue and webpack) (Fetcher.js):



import AWS from 'aws'

AWS.config.update({
region: 'ca-central-1',
accesssKeyId: 'local',
secretAccessKey: 'local',
endpoint: 'http://localhost:8000',
sslEnabled: false,
maxRetries: 5
})

const docClient = new AWS.DynamoDB.DocumentClient()

docClient.get({
Key: {
hash: 'general-info',
},
TableName: 'test'
}, (err, data) => {...})

docClient.batchGet({
RequestItems: {
'test': {
Keys: [...]
}
}
}, (err, data) => {...})


error:



Access to XMLHttpRequest at 'http://localhost:8000/' from origin 8080/test:1 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

POST http://localhost:8000/ 400 (Bad Request) aws-sdk.min.js:53

Error: Network Failure Fetcher.js:151
at XMLHttpRequest.<anonymous> (aws-sdk.min.js:53)









share|improve this question






















  • POST localhost:8000 400 (Bad Request) aws-sdk.min.js:53 ← So you don’t have a CORS problem. Instead you have a 400 Bad Request problem. The only reason you see mention of Access-Control-Allow-Origin in the error message is because servers don’t add application-configured response headers to 4xx error responses; they only add them to 2xx success responses. Anyway, the server is telling you that the request your code sent isn’t formatted in the way it expects.
    – sideshowbarker
    Nov 12 '18 at 22:02










  • @sideshowbarker, omg your right, it had nothing to do with CORS. The issue was in my batchGet I get the HASH key and RANGE key from a string by splitting it via the -, which is string HASH and a number RANGE, I just forgot to cast the Number(). I guess I saw the CORS and just could not let it go. Thank you, at least you helped me cut through my stupidity there.
    – Drew
    Nov 13 '18 at 3:53












  • Glad you got it resolved. Anyway, as far as how you initially interpreted the error, you’re not alone — the browser message for this case is misleading, and a common reaction is to take it as an indication that there’s some CORS misconfiguration. So that browser message would be less misleading and more helpful if it cited the status code of the response right at the beginning of the message rather than at the end…
    – sideshowbarker
    Nov 13 '18 at 7:18
















0












0








0







I am having issues with Cross-Origin access with a docker dynamodb-local container. I spin up the container, throw in some generated data, and in the script from the browser (using AWS sdk) connect to it locally. It is able to pull the first item (a general data entry) from a docClient.get(...). Then I browse to a different path, where a docClient.batchGet(...) is run, where the Cross-Origin Request Blocked error occurs. I cannot find out why.



I have -cors "*" set in the dynamodb-local, I did think that maybe my OS was blocking cors somehow, but I do not have NGINX or apache (or other) running/installed. No firewall running, nothing else on my Linux system that could interfere, I think. I am sure that docker itself does not care and lets the container worry about CORS. Issue persists and tested in Chromium and Firefox.



Steps:




  1. Spin up docker container,

  2. Add generated data to database

  3. Launch webpack dev-server (localhost:8080)

  4. Browse to localhost:8080, (docClient.get works, gets general-data)

  5. Browse to localhost:8080/test, (docClient.batchGet causes CORS error).


Docker:



clone of https://github.com/cnadiminti/docker-dynamodb-local



with docker-entry.sh changed to:



#!/user/bin/env bash
set -e

exec java -Djava.library.path=/var/dynamodb_local/ ${JAVA_OPTS} -jar /var/dynamodb_local/DynamoDBLocal.jar -part ${DYNAMODB_PORT} -cors "*" "$@"


which is spun up with docker run -d -p 8000:8000 --name dynamodb my-dynamodb.



Data is then generated and placed in the database.



In the browser (vue and webpack) (Fetcher.js):



import AWS from 'aws'

AWS.config.update({
region: 'ca-central-1',
accesssKeyId: 'local',
secretAccessKey: 'local',
endpoint: 'http://localhost:8000',
sslEnabled: false,
maxRetries: 5
})

const docClient = new AWS.DynamoDB.DocumentClient()

docClient.get({
Key: {
hash: 'general-info',
},
TableName: 'test'
}, (err, data) => {...})

docClient.batchGet({
RequestItems: {
'test': {
Keys: [...]
}
}
}, (err, data) => {...})


error:



Access to XMLHttpRequest at 'http://localhost:8000/' from origin 8080/test:1 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

POST http://localhost:8000/ 400 (Bad Request) aws-sdk.min.js:53

Error: Network Failure Fetcher.js:151
at XMLHttpRequest.<anonymous> (aws-sdk.min.js:53)









share|improve this question













I am having issues with Cross-Origin access with a docker dynamodb-local container. I spin up the container, throw in some generated data, and in the script from the browser (using AWS sdk) connect to it locally. It is able to pull the first item (a general data entry) from a docClient.get(...). Then I browse to a different path, where a docClient.batchGet(...) is run, where the Cross-Origin Request Blocked error occurs. I cannot find out why.



I have -cors "*" set in the dynamodb-local, I did think that maybe my OS was blocking cors somehow, but I do not have NGINX or apache (or other) running/installed. No firewall running, nothing else on my Linux system that could interfere, I think. I am sure that docker itself does not care and lets the container worry about CORS. Issue persists and tested in Chromium and Firefox.



Steps:




  1. Spin up docker container,

  2. Add generated data to database

  3. Launch webpack dev-server (localhost:8080)

  4. Browse to localhost:8080, (docClient.get works, gets general-data)

  5. Browse to localhost:8080/test, (docClient.batchGet causes CORS error).


Docker:



clone of https://github.com/cnadiminti/docker-dynamodb-local



with docker-entry.sh changed to:



#!/user/bin/env bash
set -e

exec java -Djava.library.path=/var/dynamodb_local/ ${JAVA_OPTS} -jar /var/dynamodb_local/DynamoDBLocal.jar -part ${DYNAMODB_PORT} -cors "*" "$@"


which is spun up with docker run -d -p 8000:8000 --name dynamodb my-dynamodb.



Data is then generated and placed in the database.



In the browser (vue and webpack) (Fetcher.js):



import AWS from 'aws'

AWS.config.update({
region: 'ca-central-1',
accesssKeyId: 'local',
secretAccessKey: 'local',
endpoint: 'http://localhost:8000',
sslEnabled: false,
maxRetries: 5
})

const docClient = new AWS.DynamoDB.DocumentClient()

docClient.get({
Key: {
hash: 'general-info',
},
TableName: 'test'
}, (err, data) => {...})

docClient.batchGet({
RequestItems: {
'test': {
Keys: [...]
}
}
}, (err, data) => {...})


error:



Access to XMLHttpRequest at 'http://localhost:8000/' from origin 8080/test:1 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

POST http://localhost:8000/ 400 (Bad Request) aws-sdk.min.js:53

Error: Network Failure Fetcher.js:151
at XMLHttpRequest.<anonymous> (aws-sdk.min.js:53)






javascript docker cors amazon-dynamodb






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '18 at 18:33









Drew

3802421




3802421












  • POST localhost:8000 400 (Bad Request) aws-sdk.min.js:53 ← So you don’t have a CORS problem. Instead you have a 400 Bad Request problem. The only reason you see mention of Access-Control-Allow-Origin in the error message is because servers don’t add application-configured response headers to 4xx error responses; they only add them to 2xx success responses. Anyway, the server is telling you that the request your code sent isn’t formatted in the way it expects.
    – sideshowbarker
    Nov 12 '18 at 22:02










  • @sideshowbarker, omg your right, it had nothing to do with CORS. The issue was in my batchGet I get the HASH key and RANGE key from a string by splitting it via the -, which is string HASH and a number RANGE, I just forgot to cast the Number(). I guess I saw the CORS and just could not let it go. Thank you, at least you helped me cut through my stupidity there.
    – Drew
    Nov 13 '18 at 3:53












  • Glad you got it resolved. Anyway, as far as how you initially interpreted the error, you’re not alone — the browser message for this case is misleading, and a common reaction is to take it as an indication that there’s some CORS misconfiguration. So that browser message would be less misleading and more helpful if it cited the status code of the response right at the beginning of the message rather than at the end…
    – sideshowbarker
    Nov 13 '18 at 7:18




















  • POST localhost:8000 400 (Bad Request) aws-sdk.min.js:53 ← So you don’t have a CORS problem. Instead you have a 400 Bad Request problem. The only reason you see mention of Access-Control-Allow-Origin in the error message is because servers don’t add application-configured response headers to 4xx error responses; they only add them to 2xx success responses. Anyway, the server is telling you that the request your code sent isn’t formatted in the way it expects.
    – sideshowbarker
    Nov 12 '18 at 22:02










  • @sideshowbarker, omg your right, it had nothing to do with CORS. The issue was in my batchGet I get the HASH key and RANGE key from a string by splitting it via the -, which is string HASH and a number RANGE, I just forgot to cast the Number(). I guess I saw the CORS and just could not let it go. Thank you, at least you helped me cut through my stupidity there.
    – Drew
    Nov 13 '18 at 3:53












  • Glad you got it resolved. Anyway, as far as how you initially interpreted the error, you’re not alone — the browser message for this case is misleading, and a common reaction is to take it as an indication that there’s some CORS misconfiguration. So that browser message would be less misleading and more helpful if it cited the status code of the response right at the beginning of the message rather than at the end…
    – sideshowbarker
    Nov 13 '18 at 7:18


















POST localhost:8000 400 (Bad Request) aws-sdk.min.js:53 ← So you don’t have a CORS problem. Instead you have a 400 Bad Request problem. The only reason you see mention of Access-Control-Allow-Origin in the error message is because servers don’t add application-configured response headers to 4xx error responses; they only add them to 2xx success responses. Anyway, the server is telling you that the request your code sent isn’t formatted in the way it expects.
– sideshowbarker
Nov 12 '18 at 22:02




POST localhost:8000 400 (Bad Request) aws-sdk.min.js:53 ← So you don’t have a CORS problem. Instead you have a 400 Bad Request problem. The only reason you see mention of Access-Control-Allow-Origin in the error message is because servers don’t add application-configured response headers to 4xx error responses; they only add them to 2xx success responses. Anyway, the server is telling you that the request your code sent isn’t formatted in the way it expects.
– sideshowbarker
Nov 12 '18 at 22:02












@sideshowbarker, omg your right, it had nothing to do with CORS. The issue was in my batchGet I get the HASH key and RANGE key from a string by splitting it via the -, which is string HASH and a number RANGE, I just forgot to cast the Number(). I guess I saw the CORS and just could not let it go. Thank you, at least you helped me cut through my stupidity there.
– Drew
Nov 13 '18 at 3:53






@sideshowbarker, omg your right, it had nothing to do with CORS. The issue was in my batchGet I get the HASH key and RANGE key from a string by splitting it via the -, which is string HASH and a number RANGE, I just forgot to cast the Number(). I guess I saw the CORS and just could not let it go. Thank you, at least you helped me cut through my stupidity there.
– Drew
Nov 13 '18 at 3:53














Glad you got it resolved. Anyway, as far as how you initially interpreted the error, you’re not alone — the browser message for this case is misleading, and a common reaction is to take it as an indication that there’s some CORS misconfiguration. So that browser message would be less misleading and more helpful if it cited the status code of the response right at the beginning of the message rather than at the end…
– sideshowbarker
Nov 13 '18 at 7:18






Glad you got it resolved. Anyway, as far as how you initially interpreted the error, you’re not alone — the browser message for this case is misleading, and a common reaction is to take it as an indication that there’s some CORS misconfiguration. So that browser message would be less misleading and more helpful if it cited the status code of the response right at the beginning of the message rather than at the end…
– sideshowbarker
Nov 13 '18 at 7:18














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268106%2fcors-issue-with-docker-dynamodb-local%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268106%2fcors-issue-with-docker-dynamodb-local%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()