home2 ๊ฒŒ์‹œํŒ Next.js ๊ฒŒ์‹œํŒ aws ๋ฐฐํฌ ์‹คํŒจ

aws ๋ฐฐํฌ ์‹คํŒจ

  • ์ด ์ฃผ์ œ์—๋Š” 8๊ฐœ ๋‹ต๋ณ€, 2๋ช… ์ฐธ์—ฌ๊ฐ€ ์žˆ์œผ๋ฉฐ codingapple๊ฐ€ 2 ๋…„, 9 ์›” ์ „์— ์ „์— ๋งˆ์ง€๋ง‰์œผ๋กœ ์—…๋ฐ์ดํŠธํ–ˆ์Šต๋‹ˆ๋‹ค.
9 ๊ธ€ ๋ณด์ž„ - 1 ์—์„œ 9 ๊นŒ์ง€ (์ด 9 ์ค‘์—์„œ)
  • ๊ธ€์“ด์ด
    ๊ธ€
  • #81955

    ์ •์ค‘์‹
    ์ฐธ๊ฐ€์ž
    
    ์ด๋Ÿฐ ํ™”๋ฉด์ธ๋ฐ์š” ์™œ ์‹คํŒจํ–ˆ๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค.
    
    vercel์—๋„ ๋ฐฐํฌ๋ฅผ ํ•ด๋ดค๋Š”๋ฐ
    
    Comment.js ๋ชจ๋“ˆ์„ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค๊ณ ํ•˜๋„ค์š” ํ˜น์‹œ ์ œ๊ฐ€ ๋ญ˜ ์ž˜๋ชปํ•œ๊ฑธ๊นŒ์š”?
    
    
    /app/detail/[id]/page.js
    // dynamic route
    // (props)=>{}; ํ•˜๊ณ ,
    // console.log(props); ํ•ด์ฃผ๋ฉด ์œ ์ €๊ฐ€ ๋‹ค์ด๋‚˜๋ฏน๋ผ์šฐํ„ฐ ์ž๋ฆฌ์—์ž…๋ ฅํ•œ ๊ฐ’์ด ์ฝ˜์†”์—๋œธ
    // ๋‹ค์ด๋‚˜๋ฏน๋ผ์šฐํ„ฐ๋ž€?${id}๋ฅผ๋œปํ•จ ์ „์ฒด์—์‹œ=> localhost:3000:/detail/${id}
    import { connectDB } from '@/util/database';
    import { ObjectId } from 'mongodb';
    import Link from 'next/link';
    import Comment from './Comment';
    import PostLike from '../../../component/PostLike';
    import { getServerSession } from 'next-auth';
    import { authOptions } from '@/pages/api/auth/[...nextauth]';
    import { notFound } from 'next/navigation';
    const Detail = async (props) => {
      const session = await getServerSession(authOptions);
      let client = await connectDB;
      const db = client.db('forum');
      let result = await db
        .collection('post')
        .findOne({ _id: new ObjectId(props.params.id) });
      let postLike = await db
        .collection('postLike')
        .find({ postId: new ObjectId(props.params.id) })
        .toArray();
      if (result === null) {
        return notFound();
      }
      return (
        <div className='container'>
          <h4 className='title mt-2 mb-3 '>์ƒ์„ธํŽ˜์ด์ง€</h4>
          {result && (
            <div className='list'>
              <div className='list-item'>
                {session && (
                  <div className='emoticon-box'>
                    <Link href={`/edit/${result._id}`}>โœ๏ธ</Link>โŒ
                  </div>
                )}
                <h4>
                  <span>{result.title}</span>
                </h4>
                <span className='post-like-count'> ๏ฝฅ {postLike.length}</span>
                <p>{result.contents}</p>
                <PostLike postId={props.params.id} session={session} />
                <Comment postId={result._id.toString()} />
              </div>
            </div>
          )}
        </div>
      );
    };
    export default Detail;
    Comment.js์ž…๋‹ˆ๋‹ค
    
    'use client';
    import { useEffect, useState } from 'react';
    const Comment = ({ postId }) => {
      const [comment, setComment] = useState('');
      const [commentList, setCommentList] = useState([]);
      const [isComment, setIsComment] = useState(false);
      const [loading, setLoading] = useState(false);
      const onChangeCommentInput = (e) => {
        setComment(e.target.value);
      };
      const onSubmit = () => {
        fetch('/api/comment/new', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            comment,
            postId,
          }),
        }).then((data) => {
          if (data.status === 200) {
            setIsComment((prev) => !prev);
            setComment('');
          }
        });
      };
      useEffect(() => {
        setLoading(true);
        fetch(`/api/comment/list?id=${postId}`)
          .then((response) => response.json())
          .then((data) => {
            setLoading(false);
            setCommentList(data);
          });
      }, [isComment]);
      return (
        <div className='comment-wrap'>
          <div style={{ marginBottom: '.5rem' }}>๋Œ“๊ธ€ ๋ชฉ๋ก</div>
          {loading ? (
            <div className='loading'>Loading...</div>
          ) : (
            <>
              {commentList &&
                commentList.map((data) => (
                  <div key={data._id} className='comment-list'>
                    <p className='comment-item'>
                      {data.content} &nbsp; by- &nbsp;
                      <span className='comment-name'>{data.authorName}</span>
                    </p>
                  </div>
                ))}
            </>
          )}
          <div className='comment-input-wrap'>
            <input
              type='text'
              value={comment}
              onChange={(e) => onChangeCommentInput(e)}
              className='comment-input'
            />
            <button onClick={onSubmit} style={{ width: '25%' }}>
              ๋Œ“๊ธ€์ž‘์„ฑ
            </button>
          </div>
        </div>
      );
    };
    export default Comment;
     
    
    
    #82015

    codingapple
    ํ‚ค ๋งˆ์Šคํ„ฐ
    IAM ๊ฒ€์ƒ‰ - ์—ญํ•  ๋“ค์–ด๊ฐ€์„œ https://stackoverflow.com/a/72682542 ์ด๋Ÿฐ๊ฑฐ ํ•ด๋ด…์‹œ๋‹ค 
    Comment.js ํŒŒ์ผ ๊ฒฝ๋กœ๊ฐ€ ์ž˜๋ชป๋œ๊ฒŒ ์•„๋‹๊นŒ์š”
    #82166

    ์ •์ค‘์‹
    ์ฐธ๊ฐ€์ž
    
    
    
    
    ์„ ์ƒ๋‹˜ ์—ฌ๊ธฐ์„œ ์ฝ”๋“œ์—…๋กœ๋“œ ์ €๊ฑฐ ์„ ํƒํ•ด์„œ ์ œ ํ”„๋กœ์ ํŠธ ์••์ถ•ํ•œ๊ฑฐ ์˜ฌ๋ฆฌ๋ฉด๋˜๋Š”๊ฑฐ๋งž์„๊นŒ์š”?
    #82168

    ์ •์ค‘์‹
    ์ฐธ๊ฐ€์ž
    
    
    ๊ฐ•์˜ ๊ธ€๊ณผ๋Š” ์ข€ ๋‹ค๋ฅด๋”๋ผ๊ตฌ์š” ์ด๋Ÿฐ์‹์œผ๋กœํ–ˆ๋Š”๋ฐ ์„ค์ • ๋งž๊ฒŒํ•œ๊ฑธ๊นŒ์š”..
    aws๋Š” ์š”๊ธˆํญํƒ„๋งž์„๊นŒ๋ด ๋ญ”๊ฐ€ ์กฐ์‹ฌ์Šค๋Ÿฝ๋„ค์š”
    
    
    ์ด๋ฒˆ์—” ๋‹ค๋ฅธ ์˜ค๋ฅ˜๋ฅผ ๋งˆ์ฃผ์ณค์Šต๋‹ˆ๋‹ค. ์ œ๊ฐ€ ์ž˜๋ชป๋งŒ์ง„๊ฒŒ ๋ถ„๋ช…ํ•˜๊ธดํ•œ๋ฐ ์–ด๋ ต๋„ค์š”..
    #82258

    codingapple
    ํ‚ค ๋งˆ์Šคํ„ฐ
    package.jsonํŒŒ์ผ ๋นผ๊ณ  ์˜ฌ๋ ธ๋‹ค๋Š”๊ฑฐ๊ฐ™์Šต๋‹ˆ๋‹ค ๋กœ๊ทธ๋ฉ”๋‰ด์—์„œ ์—๋Ÿฌ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅํ•ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
    #82504

    ์ •์ค‘์‹
    ์ฐธ๊ฐ€์ž
    ์˜ค ์Œค ์ œ๊ฐ€ ์••์ถ•์„ ์ž˜๋ชปํ–ˆ์—ˆ๋‚˜๋ด์š”. 
    ์••์ถ• ํ•˜๊ณ  ํ•˜๋‹ˆ๊นŒ ์ด๋ฒˆ์—” ์—๋Ÿฌ๋ฉ”์‹œ์ง€๊ฐ€ ๋ฐ”๋€Œ์—ˆ๊ณ  ์‚ฌ์ดํŠธ ๋“ค์–ด๊ฐ€๋ณด๋ฉด 502 Bad Gateway ๋ผ๋Š” ๋ฌธ๊ตฌ๊ฐ€ ๋‚˜์˜ค๋„ค์š”
    
    
    ์ด ์—๋Ÿฌ๋ฌธ๊ตฌ๋Š” ์ œ๊ฐ€ I am ์—ญํ• ์„ค์ •์„ ์ž˜๋ชปํ•ด์ค€๊ฑด๊ฐ€์š”?
    #82656

    codingapple
    ํ‚ค ๋งˆ์Šคํ„ฐ
    ๊ทธ๋Ÿด์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค ์–ด๋–ป๊ฒŒ ์„ค์ •ํ–ˆ์Šต๋‹ˆ๊นŒ
    #82706

    ์ •์ค‘์‹
    ์ฐธ๊ฐ€์ž
    I AM ์‚ฌ์šฉ์ž ์—ญํ• ์— AWSServiceRoleForElasticBeanstalk ์„ค์ •์ด ๋˜์–ด์žˆ๋Š”๊ฒŒ ๊ธฐ๋ณธ์ ์œผ๋กœ์žˆ์–ด์„œ ๊ทธ๊ฑธ ์‚ฌ์šฉํ–‡์Šต๋‹ˆ๋‹ค.
    ์‚ฌ์ง„์ฒ˜๋Ÿผ์š”. 
    ์‚ฌ์ง„์€ ์•ฑ๋งŒ๋“ค๊ณ , ํ™˜๊ฒฝ๊ตฌ์„ฑํ•˜๋Š” ๋‹จ๊ณ„์ค‘ ์„œ๋น„์Šค ์•ก์„ธ์Šค ๊ตฌ์„ฑ ๋‹จ๊ณ„์ž…๋‹ˆ๋‹ค.
    ์œ ํŠœ๋ธŒ๋„ ๋’ค์ ธ๋ณด๊ณ  ํ–ˆ๋Š”๋ฐ ์œ ํŠœ๋ธŒ์™€ ๊ฐ•์‚ฌ๋‹˜ ํ™”๋ฉด๊ตฌ์„ฑ์ด ์ œ ํ™”๋ฉด๊ตฌ์„ฑ๊ณผ ๋‹ฌ๋ผ์„œ ํ—ค๋งค๊ณ ์žˆ๋„ค์š”..
    
    
    ๊ทผ๋ฐ EC2  ์ธ์Šคํ„ด์Šค ํ”„๋กœํŒŒ์ผ์ด ๋น„์–ด์žˆ์–ด์š” ๋ˆŒ๋Ÿฌ๋ณด๋ฉด ๋ญ ์•„๋ฌด๊ฒƒ๋„ ์—†์Šต๋‹ˆ๋‹ค.
    
    ํ˜น์‹œ ์—ฌ๊ธฐ๋ฅผ ์„ค์ •ํ•ด์ค˜์•ผํ•˜๋‚˜์š”?
    
    ์ถ”๊ฐ€๋กœ ์ œ I am ์‚ฌ์šฉ์ž ์—ญํ• ์€ ์ด๋Ÿฐ์‹์œผ๋กœ ํ•ด์ค˜์žˆ์Šต๋‹ˆ๋‹ค.
    
    
    
    ๋งž๊ฒŒ ํ•œ๊ฑธ๊นŒ์š”?
    
    
    ++++ ์ถ”๊ฐ€
    
    The instance profile aws-elasticbeanstalk-ec2-role associated with the environment does not exist.
    ๋ผ๋Š” ์˜ค๋ฅ˜๊ฐ€ ๊ณ„์†๋œจ๋Š”๋ฐ..  ์ œ ์—ญํ• ์€ ์•„๋ž˜ ์‚ฌ์ง„๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
    
    
    
    ์—ฌ๊ธฐ์„œ aws-elasticbeanstalk-ec2-role๋ผ๋Š” ์ด๋ฆ„์ด ์—†์–ด์„œ ๊ทธ๋Ÿฐ๊ฑธ๊นŒ์š”?
    jung ์—ญํ•  ๊ถŒํ•œ์€ ๋‹ค์Œ๊ณผ๊ฐ™์ด ์ˆ˜์ •ํ•ด์คฌ์Šต๋‹ˆ๋‹ค.
    
    
    #82779

    codingapple
    ํ‚ค ๋งˆ์Šคํ„ฐ
    https://codingapple.com/forums/topic/aws-%eb%b0%b0%ed%8f%ac-%eb%ac%b8%ec%a0%9c/
    ์—ฌ๊ธฐ์ฒ˜๋Ÿผ ์—ญํ• 2๊ฐœ๋ž‘ ๊ถŒํ•œ ๋˜‘๊ฐ™์ด ์„ค์ •ํ•ด๋ด…์‹œ๋‹ค
9 ๊ธ€ ๋ณด์ž„ - 1 ์—์„œ 9 ๊นŒ์ง€ (์ด 9 ์ค‘์—์„œ)
  • ๋‹ต๋ณ€์€ ๋กœ๊ทธ์ธ ํ›„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

About

ํ˜„์žฌ ์›” 700๋ช… ์‹ ๊ทœ์ˆ˜๊ฐ•์ค‘์ž…๋‹ˆ๋‹ค.

  (09:00~20:00) ๋น ๋ฅธ ์ƒ๋‹ด์€ ์นดํ†ก ํ”Œ๋Ÿฌ์Šค์นœ๊ตฌ ์ฝ”๋”ฉ์• ํ”Œ (๋งํฌ)
  admin@codingapple.com
  ์ด์šฉ์•ฝ๊ด€, ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ
โ“’ Codingapple, ๊ฐ•์˜ ์˜ˆ์ œ, ์˜์ƒ ๋ณต์ œ ๊ธˆ์ง€
top

ยฉ Codingapple, All rights reserved. ์Šˆํผ๋กœ์ผ“ ์—๋“€์ผ€์ด์…˜ / ์„œ์šธํŠน๋ณ„์‹œ ๊ฐ•๋™๊ตฌ ๊ณ ๋•๋กœ 19๊ธธ 30 / ์‚ฌ์—…์ž๋“ฑ๋ก๋ฒˆํ˜ธ : 212-26-14752 ์˜จ๋ผ์ธ ๊ต์œกํ•™์›์—… / ํ†ต์‹ ํŒ๋งค์—…์‹ ๊ณ ๋ฒˆํ˜ธ : ์ œ 2017-์„œ์šธ๊ฐ•๋™-0002 ํ˜ธ / ๊ฐœ์ธ์ •๋ณด๊ด€๋ฆฌ์ž : ๋ฐ•์ข…ํ