작성
·
2.1K
0
안녕하세요 제로초님 ㅜㅜ 계속 피드백 주셔서 정말 감사합니다!!
강의 듣다 해결되지 않는 부분이 있어 혼자 찾던중 질문드립니다
aws-sdk와 multer-s3설치 후에 이미지를 업로드 하려 하니
404 not found 에러가 뜹니다 ㅜ
이러한 에러가 뜨는데 무엇이 문제인지 모르겠어 질문드립니다
보시다시피 s3에 sns-img라는 버킷을 만들었고
back/post.js에
코딩 또한 제대로 입력을 하였는데 왜 404 not found라는 에러가 뜨는지 모르겠습니다 ㅜ
pm2 logs --err --lines 200 를 백엔드 서버 터미널에 쳐보니
root@ip-172-31-7-245:/home/ubuntu/VUE.SNS/ch1/back# pm2 logs --err --lines 200
[TAILING] Tailing last 200 lines for [all] processes (change the value with --lines option)
/root/.pm2/logs/app-error.log last 200 lines:
0|app | - /home/ubuntu/VUE.SNS/ch1/back/app.js
0|app | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
0|app | at Module.Hook._require.Module.require (/home/ubuntu/VUE.SNS/ch1/back/node_modules/require-in-the-middle/index.js:61:29)
0|app | at require (internal/modules/cjs/helpers.js:92:18)
0|app | at Object.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/routes/post.js:4:13)
0|app | at Module._compile (internal/modules/cjs/loader.js:1072:14)
0|app | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
0|app | at Module.load (internal/modules/cjs/loader.js:937:32)
0|app | at Function.Module._load (internal/modules/cjs/loader.js:778:12)
0|app | at Module.require (internal/modules/cjs/loader.js:961:19)
0|app | at Module.Hook._require.Module.require (/home/ubuntu/VUE.SNS/ch1/back/node_modules/require-in-the-middle/index.js:80:39) {
0|app | code: 'MODULE_NOT_FOUND',
0|app | requireStack: [
0|app | '/home/ubuntu/VUE.SNS/ch1/back/routes/post.js',
0|app | '/home/ubuntu/VUE.SNS/ch1/back/app.js'
0|app | ]
0|app | }
0|app | Error: Cannot find module 'aws-sdk'
0|app | Require stack:
0|app | - /home/ubuntu/VUE.SNS/ch1/back/routes/post.js
0|app | - /home/ubuntu/VUE.SNS/ch1/back/app.js
0|app | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
0|app | at Module.Hook._require.Module.require (/home/ubuntu/VUE.SNS/ch1/back/node_modules/require-in-the-middle/index.js:61:29)
0|app | at require (internal/modules/cjs/helpers.js:92:18)
0|app | at Object.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/routes/post.js:4:13)
0|app | at Module._compile (internal/modules/cjs/loader.js:1072:14)
0|app | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
0|app | at Module.load (internal/modules/cjs/loader.js:937:32)
0|app | at Function.Module._load (internal/modules/cjs/loader.js:778:12)
0|app | at Module.require (internal/modules/cjs/loader.js:961:19)
0|app | at Module.Hook._require.Module.require (/home/ubuntu/VUE.SNS/ch1/back/node_modules/require-in-the-middle/index.js:80:39) {
0|app | code: 'MODULE_NOT_FOUND',
0|app | requireStack: [
0|app | '/home/ubuntu/VUE.SNS/ch1/back/routes/post.js',
0|app | '/home/ubuntu/VUE.SNS/ch1/back/app.js'
0|app | ]
0|app | }
0|app | Error: Cannot find module 'aws-sdk'
0|app | Require stack:
0|app | - /home/ubuntu/VUE.SNS/ch1/back/routes/post.js
0|app | - /home/ubuntu/VUE.SNS/ch1/back/app.js
0|app | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
0|app | at Module.Hook._require.Module.require (/home/ubuntu/VUE.SNS/ch1/back/node_modules/require-in-the-middle/index.js:61:29)
0|app | at require (internal/modules/cjs/helpers.js:92:18)
0|app | at Object.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/routes/post.js:4:13)
0|app | at Module._compile (internal/modules/cjs/loader.js:1072:14)
0|app | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
0|app | at Module.load (internal/modules/cjs/loader.js:937:32)
0|app | at Function.Module._load (internal/modules/cjs/loader.js:778:12)
0|app | at Module.require (internal/modules/cjs/loader.js:961:19)
0|app | at Module.Hook._require.Module.require (/home/ubuntu/VUE.SNS/ch1/back/node_modules/require-in-the-middle/index.js:80:39) {
0|app | code: 'MODULE_NOT_FOUND',
0|app | requireStack: [
0|app | '/home/ubuntu/VUE.SNS/ch1/back/routes/post.js',
0|app | '/home/ubuntu/VUE.SNS/ch1/back/app.js'
0|app | ]
0|app | }
0|app | Error: Cannot find module 'aws-sdk'
0|app | Require stack:
0|app | - /home/ubuntu/VUE.SNS/ch1/back/routes/post.js
0|app | - /home/ubuntu/VUE.SNS/ch1/back/app.js
0|app | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
0|app | at Module.Hook._require.Module.require (/home/ubuntu/VUE.SNS/ch1/back/node_modules/require-in-the-middle/index.js:61:29)
0|app | at require (internal/modules/cjs/helpers.js:92:18)
0|app | at Object.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/routes/post.js:4:13)
0|app | at Module._compile (internal/modules/cjs/loader.js:1072:14)
0|app | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
0|app | at Module.load (internal/modules/cjs/loader.js:937:32)
0|app | at Function.Module._load (internal/modules/cjs/loader.js:778:12)
0|app | at Module.require (internal/modules/cjs/loader.js:961:19)
0|app | at Module.Hook._require.Module.require (/home/ubuntu/VUE.SNS/ch1/back/node_modules/require-in-the-middle/index.js:80:39) {
0|app | code: 'MODULE_NOT_FOUND',
0|app | requireStack: [
0|app | '/home/ubuntu/VUE.SNS/ch1/back/routes/post.js',
0|app | '/home/ubuntu/VUE.SNS/ch1/back/app.js'
0|app | ]
0|app | }
0|app | Warning: connect.session() MemoryStore is not
0|app | designed for a production environment, as it will leak
0|app | memory, and will not scale past a single process.
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | Warning: connect.session() MemoryStore is not
0|app | designed for a production environment, as it will leak
0|app | memory, and will not scale past a single process.
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | Warning: connect.session() MemoryStore is not
0|app | designed for a production environment, as it will leak
0|app | memory, and will not scale past a single process.
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | Warning: connect.session() MemoryStore is not
0|app | designed for a production environment, as it will leak
0|app | memory, and will not scale past a single process.
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | Warning: connect.session() MemoryStore is not
0|app | designed for a production environment, as it will leak
0|app | memory, and will not scale past a single process.
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
0|app | CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
0|app | at IncomingMessage.<anonymous> (/home/ubuntu/VUE.SNS/ch1/back/node_modules/aws-sdk/lib/util.js:904:34)
0|app | at IncomingMessage.emit (events.js:412:35)
0|app | at IncomingMessage.emit (domain.js:470:12)
0|app | at endReadableNT (internal/streams/readable.js:1317:12)
0|app | at processTicksAndRejections (internal/process/task_queues.js:82:21)
이렇게 뜹니다 aws-sdk를 찾을수 없다 뜨는데 분명히 강의 보면서 로컬 백엔드에서 받고 원격 백엔드에서 git pull로 받았는데 왜 저렇게 뜨는걸까요? ㅜ
cat post.js 해봐도 수정해서 커밋한 코드 잘 넘어와 있는게 확인됩니다!!ㅜ
답변 1
0
예 감사합니다!
root@ip-172-31-7-245:/home/ubuntu/VUE.SNS/ch1/back# npm ls aws-sdk
vue-nodebird-back@1.0.0 /home/ubuntu/VUE.SNS/ch1/back
└── aws-sdk@2.996.0
npm ls aws-sdk를 입력하니 이렇게 뜹니다!
강의를 따라서 s3를 만들긴 했는데 혹시 이부분이 잘못된건가요??
그냥 위처럼 s3에서 버킷을 만들고 그 버킷이름을 routes/post.js에 설정을 하면 되는건가요??
물론 const AWS const multerS3는 설정했습니다!!
콘솔에서 보면 Filelist라고 잘 뜨는거 보니 파일은 잘 선택이 되는거 같은데
당최 무엇이 문제인지 모르겠네요 ㅜ
404는 라우터 연결이 잘못된거라고밖에 볼 수 없습니다. post.js에 게시글업로드 라우터랑 이미지 업로드 라우터랑 둘 다 들어있는게 맞나요? 그리고 process.env.S3... 이것도 .env 제대로 들어있나요?
예 제로초님 process.env.S3... 이거 는 콘솔로 찍어보니 제대로 찍히는게 확인이 됩니다.
아래 보시면 post.js도 게시글 업로드 라우터와 이미지 업로드 라우터가 둘다 들어가 있구요 제로초님 코딩이랑 비교해가며 보고 있는데 차이점은 발견하지 못했습니다
무엇이 문제인지 모르겠습니다ㅜ
dotenv에 S3밑에 저렇게 추가하라는 말이
S3_ACCESS_KEY_ID=실제값
S3_SECRET_ACCESS_KEY=실제값 을
AWS_ACCESS_KEY_ID=실제값
AWS_SECRET_ACCESS_KEY=실제값
이런식으로 수정하라는 말씀인가요??
위처럼 수정을 하고 진행을 하였는데 해결이 되지 않았습니다 ㅜㅜ
이런식으로 설정하라는 말씀이군요???
이렇게 수정하고 이미지 업로드 해봤는데 여전히 같은 에러가 나타납니다 ㅜㅜ
수정하고 나서 서버 재시작 하신거죠?
지금 사실 에러가 뭔지 정확하게 모르겠습니다. 이미지 업로드 안 하고 게시글만 업로드 하는 것은 잘 되시나요?
pm2 logs --err 했던 건 과거 에러부터 다 나오는 거라서 이미 해결된 에러일 수 있습니다. pm2 monit해서 실시간으로 뜨는 에러메시지도 확인해보세요.
예 제로초님 이미지 업로드 안하고 게시글만 업로드하는것은 됩니다 그런데 이미지를 업로드하려고 이미지를 클릭하여 선택하면 위에서 보시다시피 개발자 도구 콘솔에서 Error:network error가 뜹니다 ㅜㅜ
백엔드 서버 터미널 을 pm2 monit을 통하여 확인해보니 제가 이미지를 업로드하려고 컴퓨터내에서 이미지를 선택하면
이렇게 에러가 뜹니다ㅜㅜ 계속 구글링해서 찾아보고는 있지만 모르겠네요ㅜ
구글링 해보니 바로 위에서 pm2 monit 으로 확인한 에러가 .env가 루트폴더에 없을때 발생할수 있는 에러라 하는데 콘솔로 찍어봐도 잘 나오는데 무엇이 문제인지 모르겠네요..ㅜ
구글링 해보니
aws.config.update({
region: "eu-west-1",
endpoint: "http://localhost:8080",
accessKeyId: “xxxxxx”,
secretAccessKey: “xxxxxx”
});
이렇게 endpoint가 넣어져 있는데 이걸 안넣어서 그런건가요??ㅜ
저건 ~/.aws/credentials 파일을 만드셔야 합니다.
~/.aws 폴더를 먼저 만들고(sudo mkdir ~/.aws) 그 안에 credentials 파일을 만들고(sudo vim ~/.aws/credentials) 다음 내용을 넣고 저장하세요. vim으로요
[default]
aws_access_key_id=aws키아이디
aws_secret_access_key=aws키비밀번호
예 그럼 루트폴더에 .aws폴더를 만들고 그안에 credentials.vim으로 파일을 만들어서
aws_access_key_id=aws키아이디
aws_secret_access_key=aws키비밀번호
이렇게 넣으라는 말씀이신거죠??
아 예 알겠습니다 루트폴더에 .aws 폴더 만들고 내부네 credentials 만들어서
aws_access_key_id=aws키아이디
aws_secret_access_key=aws키비밀번호
입력해보겠습니다
[default]
이거 빼먹으셨습니다... 제가 답변 드린 그대로만 하시면 됩니다.
그리고 지금 만드신 위치가 ~ 폴더가 아닙니다. ~ 폴더에 만드셔야 합니다.
아 그렇군요!!!
혹시 그럼 ~폴더에 만드라는 말씀이 무슨 말씀인지 질문해도 될까요?? 기초적인 질문인데 코딩은 처음배우는 사람이라 답변해주시면 감사하겠습니다!!
루트폴더에서 ~라는 폴더를 우선 만들어야 한다는 말씀인가요??
리눅스에서는 홈 폴더가 ~ 폴더입니다. 이미 있습니다. 그래서 제가 명령어 다 알려드렸잖아요. 그대로 치시면 됩니다.
sudo mkdir ~/.aws
sudo vim ~/.aws/credentials
예 제로초님 강의에서 나오는대로 npm i도 했습니다 혹시몰라 프론트서버 백엔드서버 터미널 둘다에서 git pull 완료 하고 npm i했는데 저런 에러가 뜹니다 ㅜ