<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>React.js &#8211; WONIZZ.LOG</title>
	<atom:link href="https://blog.wonizz.com/category/tech/reactjs/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.wonizz.com</link>
	<description>DEVELOPMENT &#38; LIFE LOG</description>
	<lastBuildDate>Fri, 21 Aug 2026 15:45:50 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.2</generator>

<image>
	<url>https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2026/08/wz-siteicon-512.png?fit=32%2C32&#038;ssl=1</url>
	<title>React.js &#8211; WONIZZ.LOG</title>
	<link>https://blog.wonizz.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">152411368</site>	<item>
		<title>[토이프로젝트] 3편 : API 구현</title>
		<link>https://blog.wonizz.com/2020/08/31/toy-project-3/</link>
					<comments>https://blog.wonizz.com/2020/08/31/toy-project-3/#respond</comments>
		
		<dc:creator><![CDATA[워니]]></dc:creator>
		<pubDate>Mon, 31 Aug 2020 06:09:15 +0000</pubDate>
				<category><![CDATA[React.js]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Tech]]></category>
		<guid isPermaLink="false">http://blog.wonizz.tk/?p=1444</guid>

					<description><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 이번시간에는 지난 토이프로젝트에서 대한 실기능에 대해서 정리를 하고자 합니다. 주로 DynamoDB에 접근을 해서 데이터를 조작하는 API들에 대해서 소개를 하고자 합니다. AWS에서는 정말 손쉽게 기능구현을 하도록 서비스를 만들어둔거 같습니다 .</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/08/31/toy-project-3/">[토이프로젝트] 3편 : API 구현</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
안녕하세요? 정리하는 개발자 워니즈입니다. 이번시간에는 지난 토이프로젝트에서 대한 실기능에 대해서 정리를 하고자 합니다. 주로 DynamoDB에 접근을 해서 데이터를 조작하는 API들에 대해서 소개를 하고자 합니다. AWS에서는 정말 손쉽게 기능구현을 하도록 서비스를 만들어둔거 같습니다 .

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/08/lambda_1.png?w=1200&#038;ssl=1" alt="토이프로젝트 3편 : API 구현 설명 이미지 1" />

크게는 기능적으로 3가지에 대해서 정리를 할예정입니다.

<ul>
<li>도서 / 예약 목록 가져오기</li>
<li>도서 예약 처리</li>
<li>도서 반납 처리</li>
</ul>

사실 기능적으로는 엄청 간단한 기능입니다.하지만, 실질적으로 람다에서 다이나모DB를 어떻게 접근하느지에 대해서 정리를 해보도록 하겠습니다.

<h2>1. cloud9을 통한 Lambda 제어</h2>

람다를 사용하다가 보면, 부딪히게 되는 문제가 있습니다. nodemodule을 압축해서 올려야 하는 문제가 있는데, 로컬에서는 잘 돌아간다고 해도 실제로 모듈을 압축해서 올리면 동작하지 않는 문제들도 있었습니다 .

이런부분을 손쉽게 해결할 수 있는 부분이 바로 AWS에서 제공하는 IDE를 활용하는 것입니다. 실행하게 되면, CloudFormation을 통해서 EC2를 생성하게 됩니다. 별다른 방화벽 오픈도 없이 바로 작업이 가능해집니다 .

<ul>
<li>실행하기</li>
</ul>

<ol>
<li>[AWS] > [Cloud9] 에 접속을 합니다.</li>
<li>[Create environment]를 선택합니다.</li>
<li>Name environment의 Name을 임의로 지정합니다. Description은 아무거나 입력해도 됩니다.</li>
<li>[Create enviroment]를 선택하여 최종 생성합니다.</li>
</ol>

그 외 나머지 설정들은 Default로 셋팅을 하면됩니다 .

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/08/lambda_2.png?w=1200&#038;ssl=1" alt="토이프로젝트 3편 : API 구현 설명 이미지 2" />

사실 여기서부터는 terminal에 접속한 형태대로 작업을 하시면 됩니다.

<ol>
<li>화면 오른쪽 위 메뉴 중 <code>AWS Resources</code>를 선택합니다.</p></li>
<li>Lambda(us-east-1)/<code>Remote Functions</code> 목록의 <code>{임의의 function}</code>를 <code>Import</code>합니다.</p></li>
<li>불러온 람다 함수로 접근하기 위해 터미널(Terminal)을 이용합니다.(

<pre><code class="line-numbers">package.json
</code></pre>

을 생성하고 dynamodb-doc 모듈을 설치합니다.)

<ol>
<li><code>$ cd getbook</code></li>
<li><code>$ npm init -y</code></li>
<li><code>$ npm i dynamodb-doc</code></li>
</ol></li>
<li><code>index.js</code>을 아래 코드와 같이 수정합니다.</p></li>
</ol>

<pre><code class="line-numbers">//모듈 선언.
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();

exports.handler = (event, context, callback) => {
    const payload = {
        TableName: 'book'
    }
    dynamo.scan(payload, (err, data) => {
                callback(null, {
                    'statusCode': 200,
                    'headers': {'Content-Type': 'application/json; charset=UTF-8', 'access-control-allow-origin': '*'},
                    'body': JSON.stringify(data)
                });
            });
};
</code></pre>

<ol start="5">
<li>작성한 람다 함수를 버전으로 배포합니다.

<ul>
<li>Lambda(us-east-1)/<code>Local Functions</code> 목록의 <code>getbook</code>를 <code>Deploy</code>합니다.</li>
</ul></li>
</ol>

<h2>2. lambda 권한 부여</h2>

람다를 초기에 생성하게 되면, 임의의 역할이 부여 됩니다. 해당 역할 그룹에 접속한 후, Dynamodb에 대한 fullacces권한을 부여합니다.

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/08/lambda_3.png?w=1200&#038;ssl=1" alt="토이프로젝트 3편 : API 구현 설명 이미지 3" />

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/08/lambda_4.png?w=1200&#038;ssl=1" alt="토이프로젝트 3편 : API 구현 설명 이미지 4" />

<h2>3. api gateway 연결</h2>

lambda function 들이 모두 만들어졌기에(위의 작업에서 목록조회, 반납, 대여 기능을 모두 완료 한 뒤) 앞에 gateway를 통해서 연결을 지어주면, 이 관문을 모두 통과해서 작업을 수행하게 됩니다.

<pre><code class="line-numbers">Amazon API Gateway는 고객이 API Gateway에서 사용할 수 있는 REST API보다 최대 71% 저렴한 고성능 RESTful API를 신속하게 구축할 수 있도록 HTTP API를 발표했습니다. HTTP API는 AWS Lambda 함수 또는 HTTP 백엔드로 프록시를 통해 전송하는 API를 구축하는 데 최적화되어 서버리스 워크로드에 적합합니다.
</code></pre>

위의 내용은 2019년 12월 경에 발표된 내용이다. API Gateway를 들어가보면, HTTP API가 신설 되어있습니다. 필자가 구축한 내용처럼 간단하게 http만으로 통신을 하도록 구현해두면, 손쉽게 구축할 수 있는 타입으로 나와있습니다.

실제로 생성하게 된 후, [개발] > [통합] 부분에 들어가면 경로 라우팅이 가능하게 셋팅을 할 수 있습니다.

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/08/lambda_5.png?w=1200&#038;ssl=1" alt="토이프로젝트 3편 : API 구현 설명 이미지 5" />

위와 같이 셋팅을 하게 되면, API gateway 도메인을 통해서 들어오는 하위 URI들에 대해서는 뒷단에 Lambda를 연결해서 결과를 return 합니다. 손쉽게 lamda들을 apigateway를 통해서 연결을 지어줬고, 바로 appliication에서 사용할 수 있도록 연결해두었습니다.

<h2>4. 마치며&#8230;</h2>

이번시간에는 API영역을 어떻게 구현하는지 lambda + apigateway + dynamodb에 대해서 정리를 해보았습니다. 상세한 소스 구현단계가 아니라 어떤식의 흐름으로 연결되는지를 정리하다보니 내용이 많이 간소화 되어있습니다. 소스의 정확한 내용은 <a class="wp-editor-md-post-content-link" href="https://github.com/wonizz/lambda-example" target="_blank" rel="noopener">워니즈 깃헙 : 람다 예제</a>에서 확인 할 수 있습니다.
<h2 class="wp-block-heading">함께 보면 좋은 글</h2>
<ul class="wp-block-list"><li><a href="https://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">[Reactjs] AWS CloudFront를 통한 CDN 적용</a></li><li><a href="https://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/">[Reactjs] 리액트 정리 3편 : state &#038; props</a></li><li><a href="https://blog.wonizz.com/2020/05/19/reactjs-build-and-deploy/">[Reactjs]  AWS Codepipeline을 통한 배포</a></li><li><a href="https://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">[Reactjs] AWS Route53을 통한 도메인 연결</a></li></ul>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/08/31/toy-project-3/">[토이프로젝트] 3편 : API 구현</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.wonizz.com/2020/08/31/toy-project-3/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1444</post-id>	</item>
		<item>
		<title>[토이프로젝트] 2 편 : 로그인 모듈 설계 (Feat.JWT)</title>
		<link>https://blog.wonizz.com/2020/08/11/toy-project-2/</link>
					<comments>https://blog.wonizz.com/2020/08/11/toy-project-2/#respond</comments>
		
		<dc:creator><![CDATA[워니]]></dc:creator>
		<pubDate>Tue, 11 Aug 2020 03:21:43 +0000</pubDate>
				<category><![CDATA[React.js]]></category>
		<category><![CDATA[Tech]]></category>
		<guid isPermaLink="false">http://blog.wonizz.tk/?p=1425</guid>

					<description><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니증입니다. 이번시간에는 지난 토이프로젝트에 대한 설계에 대하여 정리를 해볼까 합니다. 처음에는 로그인을 도입하고자 했을때, AWS의 서비스 중에서 Congnito를 활용하고 싶었습니다. 그런데 아직은 필자에게 와닿을 만큼 편리하게 사용할 방법을 찾지 못해서 다른방법을 찾아보게 되었습니다. 그러던중에 JWS(Json Web Token)을 알게 되었고, 이참에 이것을 한번 적용해서 로그인 모듈을 만들어보자라는 생각을 하게 되었습니다. jwt는 사용자 정보를&#8230;&#160;</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/08/11/toy-project-2/">[토이프로젝트] 2 편 : 로그인 모듈 설계 (Feat.JWT)</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니증입니다. 이번시간에는 지난 토이프로젝트에 대한 설계에 대하여 정리를 해볼까 합니다. 처음에는 로그인을 도입하고자 했을때, AWS의 서비스 중에서 Congnito를 활용하고 싶었습니다.  그런데 아직은 필자에게 와닿을 만큼 편리하게 사용할 방법을 찾지 못해서 다른방법을 찾아보게 되었습니다.</p>
<p>그러던중에 JWS(Json Web Token)을 알게 되었고, 이참에 이것을 한번 적용해서 로그인 모듈을 만들어보자라는 생각을 하게 되었습니다.</p>
<p>jwt는 사용자 정보를 json 객체에 담아 이를 암호화하고 해싱 작업을 거쳐 문자열 토큰을 생성하는 기술입니다. 클라이언트는 이 토큰을 HTTP Header에 추가하여 요청을 보냄으로써 사용자 인증을 얻게 됩니다.</p>
<p>지난 글은 아래를 참고 부탁드립니다.</p>
<ul>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="https://blog.wonizz.com/2020/07/28/toy-project-1/">토이프로젝트 1편 : 기획 및 아키텍처</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="https://blog.wonizz.com/2020/08/11/toy-project-2/">토이프로젝트 2편 : 로그인 모듈(jwt)</a></li>
</ul>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/08/jwt_1.png?w=1200&#038;ssl=1" alt="토이프로젝트 2 편 : 로그인 모듈 설계 (Feat.JWT) 설명 이미지 1" /></p>
<h2>1. jwt 란 무엇인가요?</h2>
<p>JWT는 이름에서 알 수 있듯이 Json으로 된 Token을 사용합니다. 그런데 JWT는 토큰 자체가 의미를 갖는 Claim 기반의 토큰 방식입니다. Claim(권한)은 사용자에 대한 프로퍼티나 속성을 의미합니다.</p>
<p>client에 대한 인증(Authentication)과 인가(Authorization)를 위한 매커니즘이 필요한데,<br />
JWT는 MSA의 인증,인가에 사용할 수 있는 서명된 JSON 이기 때문에 안성맞춤이다.</p>
<ul>
<li>토큰 기반의 인증 원리</li>
</ul>
<ol>
<li>사용자 로그인</li>
<li>서버에서 로그인 검증 절차를 완료 하고 완료되면, 토큰을 발행한다.</li>
<li>클라이언트측에서 서버로부터 전달받은 토큰을 저장하고, 서버에 요청한다.</li>
<li>서버에서는 전달된 토큰을 검증하여 결과를 리턴한다.</li>
</ol>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/08/jwt_2.png?w=1200&#038;ssl=1" alt="토이프로젝트 2 편 : 로그인 모듈 설계 (Feat.JWT) 설명 이미지 2" /></p>
<p><a class="wp-editor-md-post-content-link" href="https://medium.com/@mjkim111/json-web-token-jwt-%EC%A0%95%EB%A6%AC-abbc80570301" target="_blank" rel="noopener">참고: JSON Web Token(JWT) 정리</a></p>
<h2>2. jwt 구조</h2>
<p>JWT는 헤더(header), 정보(payload), 서명(signature) 구조로 이루어져 있습니다.</p>
<ul>
<li>header : 타입(JWT)과 알고리즘(BASE64 같은)을 담는다.</li>
<li>payload : 보통 유저정보(id같은)와 만료기간이 객체형으로 담긴다.</li>
<li>signature : header, payload를 인코딩 한 값을 합친뒤 SECRET_KEY로 해쉬한다.</li>
</ul>
<p>JWT는 <strong>.</strong> 을 구분자로 3가지의 문자열로 되어있습니다. 구조는 다음과 같이 이루어져 있습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/08/jwt_3.png?w=1200&#038;ssl=1" alt="토이프로젝트 2 편 : 로그인 모듈 설계 (Feat.JWT) 설명 이미지 3" /></p>
<p><a class="wp-editor-md-post-content-link" href="https://velopert.com/2389" target="_blank" rel="noopener">참고 : JSON Web Token 소개 및 구조</a></p>
<p>아래의 공식 jwt 사이트에 들어가서 token을 입력하게 되면, 어떤 내용인지 보이게 됩니다. 제가 임시로 발급받은 코드로 테스트를 해보았습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/08/jwt_4.png?w=1200&#038;ssl=1" alt="토이프로젝트 2 편 : 로그인 모듈 설계 (Feat.JWT) 설명 이미지 4" /></p>
<p>jwt 토큰자체는 3개의 내용으로 구분이 되어있고, 우측에 해당 내용이 정확하게 표기가 되었습니다.</p>
<h2>3. 로그인 모듈 설계</h2>
<p>필자가 구현하고자 하는 프로젝트의 로그인 모듈을 어떤식으로 설계할지에 대한 내용입니다. 어렸을적 로그인을 생각해보면 ID/PW만 입력하면 API 쪽에서 DB값 조회해서 매칭이 되면 정상 리턴 해주고 아니면, 에러를 응답하는 구조로 생각을 했엇는데요.</p>
<p>너무 허접해서&#8230; 조금더 설계답게 생각해보았습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/08/jwt_5.png?w=1200&#038;ssl=1" alt="토이프로젝트 2 편 : 로그인 모듈 설계 (Feat.JWT) 설명 이미지 5" /></p>
<p>간단하게 대충대충 flow chart로 만들어봤습니다. Start &#8211; End사이에 어떤 흐름이 있는지만 기억하면 될 것 같습니다.</p>
<ul>
<li>로그인 시도</li>
<li>user 존재 여부 확인 -> 없으면 Error(로그인 페이지 전환)</li>
<li>password 매칭 여부 확인  -> 안되면 Error(로그인 페이지 전환)</li>
<li>로그인이 정상적으로 되면, JWT 토큰 발급</li>
<li>local storage에 저장</li>
<li>Homepage 전환</li>
</ul>
<p>참으로 간단하게 설계된 로그인 페이지 인것 같습니다. 이렇게 되고, 모든 API를 호출 할때마다 header에 token정보를 같이 전달해서 토근이 만료되거나 잘못된 정보면은 API를 호출하지 못하도록 설계 했습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/08/jwt_6.png?w=1200&#038;ssl=1" alt="토이프로젝트 2 편 : 로그인 모듈 설계 (Feat.JWT) 설명 이미지 6" /></p>
<p>개별적으로 구성되어있는 Lambda 들이 동작을 할때, 제일 먼저 jwt token검증을 수행합니다. 그렇게 되고나서 정상적으로 인증절차를 거치면 그다음에 호출을 할 수 있습니다.</p>
<h2>4. 구현</h2>
<ul>
<li>로그인 Lambda</li>
</ul>
<pre><code class="line-numbers">//모듈 선언.
const crypto = require('crypto')
const jwt = require('jsonwebtoken')
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();

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

    // 0. 변수선언
    const body = JSON.parse(event.body);
    const email = body.email;
    const password = body.password;

    const encrypted = crypto.createCipher('aes-256-cbc', 'secret');
    let encryptedpw = encrypted.update(password, 'utf8', 'base64'); 
    encryptedpw += encrypted.final('base64');

    //1. 유저 정보 조회
    const payload = {
        TableName: 'user',
        //ProjectionExpression: "#email, password",    // 1. select val, test, id
        FilterExpression: "#email=:email", // 3. where val between :start and :end
        ExpressionAttributeNames: {
            "#email": "email"
        },
        ExpressionAttributeValues: {
             ":email": email
        }
    }
    dynamo.scan(payload, (err, data) => {
        data = data.Items[0];
        if(data === undefined){
            //2 . 없으면 에러  
            callback(null, {
                    'statusCode': 500,
                    'headers': {'Content-Type': 'application/json; charset=UTF-8', 'access-control-allow-origin': '*'},
                    'body': '{"message" : "ID or PW mismatched"}'
            });
        }

        //3. 있으면 패스워드 체크
        else
        //3-1. 패스워드 일치하면 jwt 발급
        if(encryptedpw === data.password){
                const token = jwt.sign({
                    id: email,
                    name: data.name
                }, (process.env.JWT_SECRET || 'JWT_SECRET'), {
                    expiresIn: '30m',
                     issuer: 'get_token_controller',
                });
                callback(null, {
                    'statusCode': 200,
                    'headers': {'Content-Type': 'application/json; charset=UTF-8'},
                    'body': '{"user" : {"email":\"' +data.email +'\","username":\"'+data.name+'\","token" : ' + JSON.stringify(token) + '}}'
                });

        }else{
        //3-2. 패스워드 일치하지 않으면 에러 
            callback(null, {
                    'statusCode': 500,
                    'headers': {'Content-Type': 'application/json; charset=UTF-8', 'access-control-allow-origin': '*'},
                    'body': '{"message" : "ID or PW mismatched"}'
            });
        }
    });
};
</code></pre>
<p>위의 Flow chart의 로직 흐름대로 개발을 진행했습니다.</p>
<p>정확하게는 아래 보이시는 부분이 jwt 모듈에서 토큰을 발급하는 내용입니다.</p>
<pre><code class="line-numbers">const token = jwt.sign({
                    id: email,
                    name: data.name
                }, (process.env.JWT_SECRET || 'JWT_SECRET'), {
                    expiresIn: '30m',
                     issuer: 'get_token_controller',
                });
</code></pre>
<h2>5. 마치며&#8230;</h2>
<p>로그인 모듈을 설계하고 개발하는 가운데 확실히 기존의 쿠키나 세션방식보다는 여러가지 장점을 갖고 있다고 느껴졌습니다. 서버에서 더이상 세션을 저장하거나 메모리를 사용해서 기록을 해두지 않기때문에 확장성이 확실히 뛰어날 것입니다.</p>
<p>또한 쿠키방식은 request가 오가며 보안상에서 위변조가 가능했을텐데 이런 부분이 개선이 된것 같습니다. 물론 jwt도 가능하다고는 하지만 HMAC이라는 해싱 알고리즘을 써서 좀더 보안상에는 탁월하다고 들었습니다.</p>
<p>다음이시간에는 API들의 설계와 작성에 대해서 소개를 하고 최종적으로는 front-end 기술에 대해서 정리를 하고 마치는 식으로 포스팅을 연재하겠습니다.</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/08/11/toy-project-2/">[토이프로젝트] 2 편 : 로그인 모듈 설계 (Feat.JWT)</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.wonizz.com/2020/08/11/toy-project-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1425</post-id>	</item>
		<item>
		<title>[Reactjs]  AWS Codepipeline을 통한 배포</title>
		<link>https://blog.wonizz.com/2020/05/19/reactjs-build-and-deploy/</link>
					<comments>https://blog.wonizz.com/2020/05/19/reactjs-build-and-deploy/#respond</comments>
		
		<dc:creator><![CDATA[워니]]></dc:creator>
		<pubDate>Tue, 19 May 2020 02:43:49 +0000</pubDate>
				<category><![CDATA[React.js]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tech]]></category>
		<guid isPermaLink="false">http://blog.wonizz.tk/?p=1231</guid>

					<description><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 이번시간에는 CI/CD에 대해서 정리를 해보고자 합니다. 프로젝트를 진행하면서, 매번 수동으로 빌드를 수행했었고, 해당 파일을 S3로 올려주는 작업을 진행했었습니다. 그러다보니 굉장히 불편한 점이 많이 있었습니다. 그래서 생각한 아이디어는 branch를 우선 2개(development &#38; master)로 운영을 하고, 개발 브랜치에 푸시가 될 때는 빌드가 된 파일을 dev s3로 올려주고, master 브랜치로 pull request로 머지가 될&#8230;&#160;</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/05/19/reactjs-build-and-deploy/">[Reactjs]  AWS Codepipeline을 통한 배포</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 이번시간에는 CI/CD에 대해서 정리를 해보고자 합니다. 프로젝트를 진행하면서, 매번 수동으로 빌드를 수행했었고, 해당 파일을 S3로 올려주는 작업을 진행했었습니다. 그러다보니 굉장히 불편한 점이 많이 있었습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_2.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 1" /></p>
<p>그래서 생각한 아이디어는 branch를 우선 2개(development &amp; master)로 운영을 하고, 개발 브랜치에 푸시가 될 때는 빌드가 된 파일을 dev s3로 올려주고, master 브랜치로 pull request로 머지가 될 때, github actions를 통해서 prd s3로 올려주어 서비스를 하도록 하는 것이였습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_1.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 2" /></p>
<p>위에 보시는 것처럼 Master 브랜치로 pull request를 통해서 merge가 될때는 github actions가 수행되도록 yaml 파일을 작성해두었습니다. 필자의 블로그의 아래 내용을 참고 해주시기 바랍니다.</p>
<p><a class="wp-editor-md-post-content-link" href="https://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/">github actions로 S3 웹호스팅 배포하기</a></p>
<p>지난 글들은 아래를 참고 해주시면 됩니다.</p>
<ul>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/06/reactjs-redux-project/">리액트 정리 1편 : redux project 소개(1)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/">리액트 정리 2편 : redux project 소개(2)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/">리액트 정리 3편 : state &#038; props</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/">리액트 정리 4편 : S3 웹호스팅</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/">리액트 정리 5편 : 소스 배포 &#8211; github actions </a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/21/lambda-edge-guide/">리액트 정리 6편 : 람다 이미지 리사이징</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">리액트 정리 7편 : CDN 적용</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">리액트 정리 8편 : 도메인 연결</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/16/reactjs-build-and-deploy/">리액트 정리 9편 : Codepipline을 통한 배포</a></li>
</ul>
<h2>1. GitHub Actions에서는 한개의 브랜치가 컨트롤이 가능하던데요?</h2>
<p>저는 CI/CD는 Github actions로 끝내려 했습니다. 그런데 개발 브랜치에 개발 내용을 푸시를 하고나서 확인할 방법이 없었습니다. 물론 로컬에서 최대한 확인을 하고나서 서버상에 올려 체크를 하는것인데, 바로 운영에 올려서 확인할 방법이 도저히 생각나지 않았습니다.</p>
<p>Github Actions에서는 또한, 한개의 project에 대해서만 액션을 제공해주기 떄문에, 개발 브랜치에 또다른 CI/CD를 적용해야만 했습니다.</p>
<p><a class="wp-editor-md-post-content-link" href="https://github.com/wonizz/productmoor-frontend" target="_blank" rel="noopener">토이프젝트 깃헙</a></p>
<p>위의 내용에서 보시면, github actions에 대한 yaml 파일을 확인 할 수 있습니다.</p>
<pre><code class="line-numbers">name: React build
on: 
  push:                               # master Branch에서 push 이벤트가 일어났을 때만 실행
    branches:
      - master
</code></pre>
<p>브랜치를 master로 지정을 해두었기 때문에 Actions 자체는 master를 배포하는데 사용하기로 했습니다.</p>
<p>그렇다면, dev branch는 어떻게 빌드를 하고 배포를 할까요? 필자는 여기서 아마존 프리티어에서 제공해주는 서비스를 최대한 이용해보자고 마음먹었습니다.</p>
<p>그리고 찾아보면 결과 아래와 같은 서비스들을 무료로 사용할 수 있었습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_3.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 3" /></p>
<p>사실, Code Deploy까지는 쓸 이유가 없는게, CodeBuild에서 S3로 업로드 할수 있는 내용이 있어서,따로 쓰지 않았습니다</p>
<h2>2. aws CodePipeline과 CodeBuild 만들기</h2>
<p>[AWS Console 접속] > [AWS CodePipeline 접속] > [파이프라인 생성] 클릭</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_4.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 4" /></p>
<p>아래와 같이 셋팅을 해줍니다.</p>
<ul>
<li>파이프라인 이름</li>
<li>IAM 역할 필요 : 현재 역할이 없으므로 신규 생성합니다.</li>
<li>기본 위치 : github 소스를 pull받고 업로드할 S3를 지정해줍니다.(커스텀은 사용자 지정위치)</li>
<li>기본 AWS 관리형 키</li>
</ul>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_5.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 5" /></p>
<p>target 소스 위치가 github에 있기 때문에 oauth를 통해서 연결 지어주는 내용입니다. 손쉽게 클릭으로 github을 연동 할 수 있고, 연동을 하게 되면, 어떤 프로젝트와 어떤 브랜치를 사용할 것인지를 선택해 줍니다.</p>
<p>선택한 저장소의 브랜치에서 변경이 감지되면 파이프라인이 동작하기 위해서 Github 웹훅을 선택해줍니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_6.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 6" /></p>
<p>다음은 빌드내용입니다. CodeBuild를 사용하기로 했으니, 공급자는 CodeBuild를 선택해 줍니다. 현재는 CodeBuild에 대한 내용을 생성하지 않았기 때문에 신규로 생성해주기 위해서 <strong>프로젝트 생성</strong>을 클릭 해줍니다.</p>
<p>그럼 자연스럽게 CodeBuild로 이동해서 생성하는 화면이 나옵니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_7.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 7" /></p>
<p>빌드할 프로젝트 이름을 입력합니다</p>
<ul>
<li>프로젝트 이름</li>
</ul>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_8.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 8" /></p>
<p>빌드할 환경을 설정하는 영역입니다.</p>
<p>필자는 운영체제를 Ubuntu로 했고 나머지는 기본값을 했습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_9.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 9" /></p>
<p>Build Spec같은 경우는 직접 입력해주는 방식을 선택했습니다.</p>
<pre><code class="line-numbers">version: 0.2
phases:
  install:
    commands:
      - echo Insatlling NPM Packages and wget Enviorment File
      - npm install
  build:
    commands:
      - echo Build started on `date`
      - npm run build
  post_build:
    commands:
      - aws s3 sync ./build s3://dev-productmoor --acl public-read
artifacts:
  files:
    - '**/*'
  name: build-$(date +%Y-%m-%d) 
  base-directory: build
cache:
  paths:
    - "node_modules/**/*"
</code></pre>
<p>하나씩 내용을 살펴보기로 하겠습니다.</p>
<pre><code class="line-numbers">version: 0.2
phases:
  install:
    commands:
      - echo Insatlling NPM Packages and wget Enviorment File
      - npm install
</code></pre>
<ul>
<li>npm install : package.json으로부터 필요한 내용을 받습니다.</li>
</ul>
<pre><code class="line-numbers">  build:
    commands:
      - echo Build started on `date`
      - npm run build
</code></pre>
<ul>
<li>npm run build : 실제 소스파일을 컴파일해서 /build 폴더 하위로 빌드 파일을 생성합니다.</li>
</ul>
<pre><code class="line-numbers">  post_build:
    commands:
      - aws s3 sync ./build s3://dev-productmoor --acl public-read
</code></pre>
<ul>
<li>s3 업로드 : 빌드한 파일을 s3로 직접 업로드 합니다.</li>
</ul>
<pre><code class="line-numbers">artifacts:
  files:
    - '**/*'
  name: build-$(date +%Y-%m-%d) 
  base-directory: build
</code></pre>
<ul>
<li>build 파일 압축 후 업로드 : 배포 후 문제가 생겼을때를 대비하여, 항상 배포된 파일들은 zip파일로 압축하여 이력을 갖고 있습니다.</li>
</ul>
<p>끝으로, 로그 관련된 내용은 cloudwatch를 선택하고 넘어갑니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_10.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 10" /></p>
<p>배포는 이미 Codebuild에서 수행하기로 했으므로(S3 업로드), 따로 구성을 하지 않고 넘어갑니다.</p>
<p>마지막으로 검토를 하게 되고 최종 생성을 클릭하여 생성합니다.</p>
<h2>3. 빌드 테스트</h2>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_11.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 11" /></p>
<p>최종적으로 파이프라인을 생성하게 되면, source를 pull받고 codebuild를 수행하게 됩니다.</p>
<p>위와 같이 정상적으로 배포가 진행이 됩니다.</p>
<h2>4. 최종 CI/CD 구성도</h2>
<p>개발/운영으로 2개의 브랜치를 나눴고, 각기 다른 서비스(깃헙액션, 코드파이프라인)을 통해서 빌드와 배포를 구성했습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/deploy_pipe_12.png?w=1200&#038;ssl=1" alt="Reactjs  AWS Codepipeline을 통한 배포 설명 이미지 12" /></p>
<p>위쪽이 운영용이고, 아랫쪽이 개발용입니다. 필자가 생각한 방식은 개발에서 검증이 다 마치면, code를 마스터로 pull request를 요청할 수 있고, 역시 웹훅 방식으로 github actions가 동작하면서 운영으로 바로 배포가 되도록 했습니다.</p>
<p>S3 앞단에 cloudfront가 있기 때문에 운영으로 잘못된 소스가 나가더라도, 캐시가 플러시 되지 않는한 문제가 생기지 않을것이라고 생각했습니다.</p>
<h2>5. 마치며..</h2>
<p>이번시간에는 CI/CD를 어떻게 구성하였는지에 대해서 정리를 했습니다. 확실히 AWS에서 제공해주는 서비스들을 사용하다보면 한개의 서비스를 만들어서 운영하는데까지 정말 편리하다고 생각이 듭니다. CI/CD를 구성해놓고 보니, 좀더 편리성을 찾고자 배포 알람에 대해서 생각해보게 되었습니다.</p>
<p>그래서 다음시간에는 AWS에서 최근에 서비스를 제공하는 Chatops를 통해서 Slack으로 연계하는 내용에 대해서 정리를 해보도록 하겠습니다.</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/05/19/reactjs-build-and-deploy/">[Reactjs]  AWS Codepipeline을 통한 배포</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.wonizz.com/2020/05/19/reactjs-build-and-deploy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1231</post-id>	</item>
		<item>
		<title>[Reactjs] AWS Route53을 통한 도메인 연결</title>
		<link>https://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/</link>
					<comments>https://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/#respond</comments>
		
		<dc:creator><![CDATA[워니]]></dc:creator>
		<pubDate>Mon, 11 May 2020 07:46:03 +0000</pubDate>
				<category><![CDATA[React.js]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tech]]></category>
		<guid isPermaLink="false">http://blog.wonizz.tk/?p=1208</guid>

					<description><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 개인으로 진행하는 프로젝트가 드디어! 👏👏 도메인 연결만을 남겨두고 있습니다. 지금까지 했던 것을 다시 정리하면, 어플리케이션 제작(Reactjs) 이미지 오리진 서버 (S3) 이미지 캐시 서버 (CloudFront) : 람다 엣지 사용 인증서 작성(아마존 인증서) 인증서 연결(CloudFront &#8211; 아마존 인증서 연결) 도메인 연결(Route53 &#8211; CloudFront 연결) 인증서 연결에 대한 내용은 간략해서 따로 정리를 하지는 않았지만,&#8230;&#160;</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">[Reactjs] AWS Route53을 통한 도메인 연결</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 개인으로 진행하는 프로젝트가 드디어! 👏👏 도메인 연결만을 남겨두고 있습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/route52_1.png?w=1200&#038;ssl=1" alt="Reactjs AWS Route53을 통한 도메인 연결 설명 이미지 1" /></p>
<p>지금까지 했던 것을 다시 정리하면,</p>
<ul>
<li>어플리케이션 제작(Reactjs)</li>
<li>이미지 오리진 서버 (S3)</li>
<li>이미지 캐시 서버 (CloudFront) : 람다 엣지 사용</li>
<li>인증서 작성(아마존 인증서)</li>
<li>인증서 연결(CloudFront &#8211; 아마존 인증서 연결)</li>
<li>도메인 연결(Route53 &#8211; CloudFront 연결)</li>
</ul>
<p>인증서 연결에 대한 내용은 간략해서 따로 정리를 하지는 않았지만, CloudFront 관련 정리 포스팅에서 보시면,</p>
<p>[CloudFront] > [Edit Distribution] > [SSL Certificate] > [Custom SSL Certificate] 선택하여 생성하신 인증서를 심어주면, 동작하게 됩니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/route53_2.png?w=1200&#038;ssl=1" alt="Reactjs AWS Route53을 통한 도메인 연결 설명 이미지 2" /></p>
<p>지난 글들은 아래를 참고 해주시면 됩니다.</p>
<ul>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/06/reactjs-redux-project/">리액트 정리 1편 : redux project 소개(1)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/">리액트 정리 2편 : redux project 소개(2)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/">리액트 정리 3편 : state &#038; props</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/">리액트 정리 4편 : S3 웹호스팅</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/">리액트 정리 5편 : 소스 배포 &#8211; github actions </a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/21/lambda-edge-guide/">리액트 정리 6편 : 람다 이미지 리사이징</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">리액트 정리 7편 : CDN 적용</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">리액트 정리 8편 : 도메인 연결</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/16/reactjs-build-and-deploy/">리액트 정리 9편 : Codepipline을 통한 배포</a></li>
</ul>
<h2>1. Route53이란 무엇인가요?</h2>
<p>자 그럼, 이제 Route53이 어떤 서비스 인지 간략하게 정리를 해보도록 하겠습니다.</p>
<blockquote><p>
  Route53이란 ec2, elb, s3 cloudfront와 연동가능한 dns서비스를 말합니다.
</p></blockquote>
<p>아쉽게도 프리티어에서는 사용이 불가한 서비스 입니다. 필자도 해당 블로그를 운영하면서 동시에 CLoudFront + Route53 조합으로 가려고 해봤는데, 비용이 발생하는걸로 바로 포기를 했습니다.</p>
<p>운이 좋게 개인 프로젝트를 진행할 기회가 생겨서 이번기회에 Route53을 사용해볼 수 있었습니다.</p>
<p>쉽게 이야기해서 DNS를 제공해주는 서비스라고 보시면됩니다. DNS라는 것은 사용자 입장에서 IP를 외워 둘수 없기 때문에 알기 쉬운 도메인과 해당 인스턴스 혹은 ELB등을 연결지어주는 서비스라고 보시면됩니다.</p>
<h3>1-1. 도메인 연결하는 방법</h3>
<ul>
<li>A Record</li>
</ul>
<p>일반적으로 많이 사용하는 IPv4방식(예 &#8211; 123.123.456.456)의 IP주소로 연결해 줍니다. 현재 가장 많이 쓰이고 있는 방법입니다.</p>
<ul>
<li>AAAA Record</li>
</ul>
<p>IPv6방식(예 &#8211; 1234:2345:3456:4567:5678)의 IP주소에 연결을 하여 줍니다. IPv6의 주소를 사용하고 있는 경우에만 관련됩니다.</p>
<ul>
<li>CNAME Record</li>
</ul>
<p>별칭이라는 이야기를 하는데, 쉽게 말씀드리면 다른 도메인 주소를 지정한 주소로 연결할 수 있게끔 해줍니다.</p>
<ul>
<li>DDNS Record</li>
</ul>
<p>개인 서버를 운영하거나 공인 IP가 유동적인 경우에는 변경된 아이피 주소를 주기적으로 갱신하여 줍니다. A Record방식과 연결방식에는 차이가 없지만 자동으로 변경된 아이피를 갱신하는냐, 아니면 직접 입력을 하느냐의 차이입니다.</p>
<ul>
<li>웹 포워딩</li>
</ul>
<p>아이피주소가 아닌 웹 주소로 직접 연결을 합니다. 웹 포워딩의 장점은 복잡한 주소를 한번에 연결할 때 편합니다. 하지만 원래 주소를 감춰서 보여주지 못합니다. (억지로 감추면 멀쩡한 웹페이지 해상도가 꼬이는 등 별별 현상이 다 일어나더군요.)</p>
<p>위의 방식들은 원래의 주소(IP주소)를 감춰서 보여주기 때문에 원래의 주소가 노출 될 일은 없지만 웹 포워딩은 원래 주소가 노출되는 불편한 점을 가지고 있습니다.</p>
<p><a class="wp-editor-md-post-content-link" href="https://velog.io/@noyo0123/Route53-%EC%97%90%EC%84%9C-host-zone-a-%EB%A0%88%EC%BD%94%EB%93%9C%EB%9E%80-adk21ictsb" target="_blank" rel="noopener">출처 : 도메인과 네임서버 그리고 Route53이란?</a></p>
<h2>2. Route53과 CloudFront 연결하기</h2>
<p>Route53을 연결하기에 앞서서 CloudFont에서 해야될 선작업을 먼저 정리하겠습니다.</p>
<ul>
<li>CloudFront 수정</li>
</ul>
<p>[CloudFonrt] > [Edit Distribution] 을 클릭합니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/route53_3.png?w=1200&#038;ssl=1" alt="Reactjs AWS Route53을 통한 도메인 연결 설명 이미지 3" /></p>
<p>그리고 나서, 위에 보시는 것처럼 <strong>Alternate Domain Names</strong>를 입력해줍니다. 그 아래 빨간 박스는 위에서 설명드린 <strong>ACM 인증</strong> 관련 된 내용입니다.</p>
<ul>
<li>Route53 도메인 연결</li>
</ul>
<p>[Route53] > [Hosted Zones] 을 클릭합니다. 기존에 domain을 Route53을 통해서 생성하였기 때문에 호스팅 영역에 존재하는 목록이 있습니다. 해당 목록을 클릭하고 들어갑니다.  [레코드 세트 생성] 을 클릭한뒤에 아래와 같이 원하는 도메인 이름을 선정합니다.</p>
<ol>
<li>이름 : www.productmoor.com</li>
<li>유형 : A &#8211; IPv4 주소</li>
<li>별칭 : 예</li>
<li>별칭 대상 : 클라우트 프론트 주소</li>
</ol>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/Route53_4.png?w=1200&#038;ssl=1" alt="Reactjs AWS Route53을 통한 도메인 연결 설명 이미지 4" /></p>
<p>입력을 한 뒤, 저장을 합니다.</p>
<ul>
<li>테스트</li>
</ul>
<p>https://www.productmoor.com 으로 접속을 해봅니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/Route53_5.png?w=1200&#038;ssl=1" alt="Reactjs AWS Route53을 통한 도메인 연결 설명 이미지 5" /></p>
<p>정상적으로 인증서도 노출이 되고, 서비스도 잘 되는 것을 볼 수 있습니다.</p>
<h2>3. 마치며..</h2>
<p>드디어.. 필자가 지난 3개월정도 제작한 어플리케이션에 대하여 서비스를 하기 시작했습니다. 아직은 미흡하지만, 그래도 처음으로 제작하는 리액트 어플리케이션이였고 서버리스로 구성을 하면서 AWS 서비스에 대해서 이것저것 배울 수 있는 좋은 기회였던 것 같습니다.</p>
<p>더군다나, 여러가지 목표도 생기기 시작했습니다. 이번에 깃헙을 통해서 어플리케이션을 제작했는데 대다수의 외부 개발자들이 1일 1커밋을 목표로 하시는 분들이 많이 있는것 같습니다. 저는 아직은 그렇게 까지는 못하더라도 1주일 2회 커밋이라도 노력을 해볼 예정입니다.</p>
<p>추가적으로 아마존 서비스들이 무궁무진하게 많아서, 여러가지 서비스들에 대해서 좀더 알아 보는 것이 목표로 생겼습니다. AWS 에서의 어플리케이션 개발은 전통적으로 수행하던 개발보다 확실히 편리해진 것 같습니다.</p>
<p>개발자가 하나하나 신경써줘야될 부분들을 매니지드로 넘기면서 동시에 인프라까지 관리를 할 수 있는 것 같습니다.</p>
<p>총 8편으로 구성된 이번 포스팅에서 미흡한 부분도 있지만, 중간중간 업데이트를 할 예정입니다. 많은 관심 부탁 드립니다^^</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">[Reactjs] AWS Route53을 통한 도메인 연결</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1208</post-id>	</item>
		<item>
		<title>[Reactjs] AWS CloudFront를 통한 CDN 적용</title>
		<link>https://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/</link>
					<comments>https://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/#respond</comments>
		
		<dc:creator><![CDATA[워니]]></dc:creator>
		<pubDate>Wed, 06 May 2020 00:34:26 +0000</pubDate>
				<category><![CDATA[React.js]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tech]]></category>
		<guid isPermaLink="false">http://blog.wonizz.tk/?p=1194</guid>

					<description><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 이번시간에는 AWS의 CDN 서비스인 CloudFront 에 대해서 정리하도록 하겠습니다. 지난 글들은 아래를 참고 해주시면 됩니다. 리액트 정리 1편 : redux project 소개(1) 리액트 정리 2편 : redux project 소개(2) 리액트 정리 3편 : state &#038; props 리액트 정리 4편 : S3 웹호스팅 리액트 정리 5편 : 소스 배포 &#8211; github actions&#8230;&#160;</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">[Reactjs] AWS CloudFront를 통한 CDN 적용</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 이번시간에는 AWS의 CDN 서비스인 <strong>CloudFront</strong> 에 대해서 정리하도록 하겠습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/cloudfront_0.png?w=1200&#038;ssl=1" alt="cloudfront_0" /></p>
<p>지난 글들은 아래를 참고 해주시면 됩니다.</p>
<ul>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/06/reactjs-redux-project/">리액트 정리 1편 : redux project 소개(1)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/">리액트 정리 2편 : redux project 소개(2)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/">리액트 정리 3편 : state &#038; props</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/">리액트 정리 4편 : S3 웹호스팅</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/">리액트 정리 5편 : 소스 배포 &#8211; github actions </a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/21/lambda-edge-guide/">리액트 정리 6편 : 람다 이미지 리사이징</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">리액트 정리 7편 : CDN 적용</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">리액트 정리 8편 : 도메인 연결</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/16/reactjs-build-and-deploy/">리액트 정리 9편 : Codepipline을 통한 배포</a></li>
</ul>
<p>필자가 진행하는 토이프로젝트는 이미지들이 주를 이루는 웹페이지입니다. 이미지들을 <strong>S3</strong>에 적재를 하고 해당 URL로 호출을 홰서 화면에 노출시켜주는 것입니다.</p>
<p>그런데, 이미지들이 모두 원본으로 올라가있고, 더군다나 사이즈가 굉장히 크기 때문에 사용자 경험에서 최악을 제공했습니다.</p>
<p>아무래도 <strong>Cache Layer</strong> 가 필요한 시점이였고, 가장 손쉽게 적용할 수 있는 것이 AWS의 CloudFront라고 생각했습니다.</p>
<h2>1. CloudFont란 무엇인가요?</h2>
<blockquote><p>
  빠르고 고도로 안전하며 프로그래밍 가능한 콘텐츠 전송 네트워크(CDN)</p>
<p>  Amazon CloudFront는 개발자 친화적 환경에서 짧은 지연 시간과 빠른 전송 속도로 데이터, 동영상, 애플리케이션 및 API를 전 세계 고객에게 안전하게 전송하는 고속 콘텐츠 전송 네트워크(CDN) 서비스입니다.
</p></blockquote>
<p>CloudFont는 다른 AWS의 서비스 와도 통합이 됩니다. 필자는 S3를 Origin으로 사용하고 CloudFront가 CDN역할을 하여 엣지 서비스를 하는 것으로 서비스를 연결할 예정입니다.</p>
<h2>2. CloudFront 설정 방법</h2>
<p>[AWS Console 접속] > [CloudFront 접속] > [Create Distribution 클릭]</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/cloudfront_1.png?w=1200&#038;ssl=1" alt="CloudFront_1" /></p>
<ul>
<li>첫번째는 .html, .css, .js 등의 배포 속도를 높이는 기능입니다.</li>
<li>두번째는 Adobe Flash Media Server의 RTMP 프로토콜을 사용하여 스트리밍 미디어 파일의 배포 속도를 높이는 서비스인데, 2020년 12월 31일부로 EOS 된다고 합니다.</li>
</ul>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/cloudfront_2.png?w=1200&#038;ssl=1" alt="CloudFont_2" /></p>
<p>[Create Distribution] 으로 들어오게 되면, 위와 같은 화면이 보입니다. 화면상에서는 크게 3개의 셋팅으로 구성되어있습니다.</p>
<ul>
<li>Origin Settings : 오리진을 어느곳으로 Mapping을 할 것인가요?</li>
<li>Default Cache Behavior Settings : Cache 정책 및 Layer에 대한 셋팅은 어떻게 할것인가요?</li>
<li>Distribution Settings : WAF, 인증서, Root Object에 대한 셋팅은 어떻게 할 것인가요?</li>
</ul>
<p>사실 위에서 <strong>빨강 박스</strong> 표시해둔곳만 셋팅하고 넘어가면됩니다. 추후에 인증서 + 도메인 연결을 위해서 변경을 수행합니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/cloudfront_3.png?w=1200&#038;ssl=1" alt="cloudfront_3" /></p>
<ul>
<li>Price Class &#8211; 퍼포먼스에 비례해서 가격이 오릅니다.</li>
<li>Alternate Domain Names &#8211; 해당 Distribution을 통해 사용할 도메인을 등록 해 줍시다.</li>
<li>SSL Certificate &#8211; Custom SSL Certificate를 선택하면 ACM에서 설정한 인증서를 불러올 수 있습니다.</li>
</ul>
<p>[Distribution Settings] 에서 위와 같이 셋팅합니다. 아직 인증서를 발급 받지 않았기 때문에 기본 cloudfront 인증서와 Root Object에서 &#8220;index.html&#8221; 을 입력해줍니다.</p>
<p>모든 셋팅이 완료 되면 우측하단에 [Create Distribution] 을 클릭하여 최종 CloudFront에 대한 배포를 수행합니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/05/cloudfront_4.png?w=1200&#038;ssl=1" alt="cloudfront_4" /></p>
<p>대략 10분이 지나면, 위의 메시지와 같이 상태코드가 [Deployed]로 변경이 됩니다. 그렇게 되면 Cloudfront를 통해서 S3의 내용을 캐싱을 하여 내려받게 됩니다.</p>
<h2>3. 테스트 수행하기</h2>
<p>정상적으로 Distribution이 완료가 되면, 다음과 같이 Cloudfront 도메인을 통해서 접속을 수행해봅니다. 필자 같은 경우 S3의 이미지들이 올려져 있고, 또한, reactjs로 build한 파일들이 올려져 있습니다.</p>
<p>모든 내용은 public access가 가능하도록 셋팅이 되어있습니다.</p>
<p>아직 도메인을 달아서 cloudfront 도메인을 공유 하지 못하지만, 정상적으로 호출이 수행됩니다! 이제 추가적으로 할 작업은 cloudfront에 ACM(인증서)를 셋팅하고 앞단에 Route53을 통해서 도메인을 연결하면됩니다.</p>
<p>Route53 -> CloudFront(With ACM) -> S3 의 순서로 호출이 수행됩니다.</p>
<h2>4. 마치며&#8230;</h2>
<p>필자가 지금까지 Reactjs앱을 제작하고, S3 웹호스팅을 통해서 직접 S3에서 호출을 수행하였습니다. 그러던중에 캐시 레이어가 필요하여 CloudFront를 도입하게 되었고 마지막 작업으로 ACM(인증서)와 Route53으로 최종 도메인 연결 작업을 할 예정입니다.</p>
<p>구축부터 인프라 구성까지 서버리스로 구성하다보니 최대한 개발에만 집중할 수 있었고, 확실히 아마존 서비스가 편리하게 구성이 되어있다는 걸 다시한번 더 느끼게 되었습니다.</p>
<p>다음 이시간에는 ACM과 Route53을 통한 도메인 연결에 대해서 정리하겠습니다.</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">[Reactjs] AWS CloudFront를 통한 CDN 적용</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1194</post-id>	</item>
		<item>
		<title>[Reactjs] S3 웹호스팅 이용하기</title>
		<link>https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/</link>
					<comments>https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/#respond</comments>
		
		<dc:creator><![CDATA[워니]]></dc:creator>
		<pubDate>Mon, 13 Apr 2020 08:26:15 +0000</pubDate>
				<category><![CDATA[React.js]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Tech]]></category>
		<guid isPermaLink="false">http://blog.wonizz.tk/?p=1128</guid>

					<description><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 이번시간에는 지난 시간까지 제작한 Reactjs 소스를 어떻게 외부에 서비스를 할지에 대한 고민들을 정리 하려고 합니다. 지금까지 개발을 하면서 AWS EC2 인스턴스에 npm 명령어를 이용해서 development 용으로 올려 두었었습니다. 필자도 이번에 리액트를 처음 개발해봤고, 개발 자체는 익히면 어렵진 않은데, 서비스 운영을 어떠한 방식으로 할지가 궁금했습니다. 그래서 Facebook 에 react korea user group&#8230;&#160;</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/">[Reactjs] S3 웹호스팅 이용하기</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
안녕하세요? 정리하는 개발자 워니즈입니다. 이번시간에는 지난 시간까지 제작한 Reactjs 소스를 어떻게 외부에 서비스를 할지에 대한 고민들을 정리 하려고 합니다. 지금까지 개발을 하면서 AWS EC2 인스턴스에 npm 명령어를 이용해서 development 용으로 올려 두었었습니다.

필자도 이번에 리액트를 처음 개발해봤고, 개발 자체는 익히면 어렵진 않은데, 서비스 운영을 어떠한 방식으로 할지가 궁금했습니다. 그래서 Facebook 에 react korea user group 에 글을 게재 하게 되었습니다.

지난 글들은 아래를 참고 해주시면 됩니다.

<ul>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/06/reactjs-redux-project/">리액트 정리 1편 : redux project 소개(1)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/">리액트 정리 2편 : redux project 소개(2)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/">리액트 정리 3편 : state &#038; props</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/">리액트 정리 4편 : S3 웹호스팅</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/">리액트 정리 5편 : 소스 배포 &#8211; github actions </a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/21/lambda-edge-guide/">리액트 정리 6편 : 람다 이미지 리사이징</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">리액트 정리 7편 : CDN 적용</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">리액트 정리 8편 : 도메인 연결</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/16/reactjs-build-and-deploy/">리액트 정리 9편 : Codepipline을 통한 배포</a></li>
</ul>

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/04/s3_web_hosting_1.png?w=1200&#038;ssl=1" alt="Reactjs S3 웹호스팅 이용하기 설명 이미지 1" />

<blockquote>
  질문) React를 빌드하고 나면 /build/ 라는 폴더내에 index.html 파일과 css/js등이 남게 됩니다. 이런가운데 EC2를 이용해서 서비스를 하는지 아니면 S3의 웹호스팅을 이용하는지 문의드립니다.
</blockquote>

글을 쓰자마자 정말 많은 분들께서 도움을 주셨습니다. 이 포스팅을 빌어 감사하다는 말씀 전해 드립니다. 기본적으로 SPA(Single Page Application) 형식으로 만드는 어플리케이션들은 대게 S3 + CloudFront + ACM(인증) + Rounte53(DNS)조합으로 많이 가는 것 같습니다.

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/04/s3_web_hosting_2.png?w=1200&#038;ssl=1" alt="Reactjs S3 웹호스팅 이용하기 설명 이미지 2" />

EC2에 서비스를 올린다면, 어찌됐든 nginx혹은 express등의 자체 서버를 기동한 뒤 거기에 /build/ 폴더를 구동하는 방식이라 필자는 최대한 비용효율적인 S3 웹호스팅을 이용하기로 했습니다.

<h2>1. S3 웹호스팅 사용하기</h2>

필자의 소스는 back DATA를 ES(Elastic Search)에서 적재하고, 이미지들은 S3에 올려주어 호스팅하고 있었습니다. 그래서 기존에 S3가 존재했기 때문에, 거기서 같이 application 까지 호스팅을 해주는 방식이 좋을 것이라고 판단했습니다.

<ul>
<li>웹호스팅 설정하기</li>
</ul>

[속성] > [정적 웹 사이트 호스팅] > [이 버킷을 사용하여 웹 사이트를 호스팅 합니다.] > [저장]

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/04/s3_web_hosting_3.png?w=1200&#038;ssl=1" alt="Reactjs S3 웹호스팅 이용하기 설명 이미지 3" />

index.html 파일을 기본적으로 서비스 하기 때문에, Document root를 index.html로 지정을 해줍니다.

<ul>
<li>파일 업로드 및 권한 설정</li>
</ul>

[권한] > [퍼블릭 액세스 차단] > [모두 해제] > [저장]

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/04/s3_web_hosting_4.png?w=1200&#038;ssl=1" alt="Reactjs S3 웹호스팅 이용하기 설명 이미지 4" />

[개요] > [업로드 파일 모두 선택] > [작업] > [퍼블릭으로 설정]

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/04/s3_web_hosting_5.png?w=1200&#038;ssl=1" alt="Reactjs S3 웹호스팅 이용하기 설명 이미지 5" />

이제 모든 준비가 되었습니다. 테스트를 통해서 정상적으로 어플리케이션이 구동하는지 테스트를 진행하면됩니다.

<h2>2. 빌드 배포는 어떻게 하나요?</h2>

사실 위에서 이야기한 내용은 필자가 수동으로 로컬 PC에서 build를 수행하고 결과물을 직접 S3에 업로드 해주어 서비스를 연결했습니다. 지난 포스팅 내용중에 github action을 통해서 빌드 수행 후, S3로 업로드 해주는 내용까지 정리를 해두었습니다. 아직 서비스에 연결은 안했지만, master 브랜치로 머지가 되는 순간 수행되도록 셋팅을 해볼까 합니다.

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/04/s3_web_hosting_6.png?w=1200&#038;ssl=1" alt="Reactjs S3 웹호스팅 이용하기 설명 이미지 6" />

<a class="wp-editor-md-post-content-link" href="https://velog.io/@bluestragglr/Github-Action%EC%9C%BC%EB%A1%9C-%EB%B0%B0%ED%8F%AC-%EC%9E%90%EB%8F%99%ED%99%94%ED%95%98%EA%B8%B0" target="_blank" rel="noopener">참조 : githubaction 으로 배포 자동화하기</a>

<h2>3. 마치며&#8230;</h2>

S3를 통해 웹호스팅을 하게되면서, origin이 S3이다보니, CDN서비스가 필요해지게 되었습니다. 그렇다면, AWS에서 제공해주는 CloudFront를 S3 앞에 붙이면됩니다. 그러면, 엣지 서비스가 되기 시작하는것인데 도메인(Rounte53)을 생성하고, 해당 도메인을 엣지에 연결해줍니다.

중간에 ACM(AWS Certification Manager)를 통해서 https 인증까지 CloudFront에 연결을 해주면 정상적으로 서비스가 될 것같습니다.

다음 이시간에는 CloudFront를 생성하여 S3에 연결하는 내용을 정리하도록 하겠습니다.
<h2 class="wp-block-heading">함께 보면 좋은 글</h2>
<ul class="wp-block-list"><li><a href="https://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">[Reactjs] AWS CloudFront를 통한 CDN 적용</a></li><li><a href="https://blog.wonizz.com/2020/08/31/toy-project-3/">[토이프로젝트] 3편 : API 구현</a></li><li><a href="https://blog.wonizz.com/2020/05/19/reactjs-build-and-deploy/">[Reactjs]  AWS Codepipeline을 통한 배포</a></li><li><a href="https://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">[Reactjs] AWS Route53을 통한 도메인 연결</a></li></ul>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/">[Reactjs] S3 웹호스팅 이용하기</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1128</post-id>	</item>
		<item>
		<title>[Reactjs] 리액트 정리 3편 : state &#038; props</title>
		<link>https://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/</link>
					<comments>https://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/#respond</comments>
		
		<dc:creator><![CDATA[워니]]></dc:creator>
		<pubDate>Mon, 06 Apr 2020 02:19:07 +0000</pubDate>
				<category><![CDATA[React.js]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tech]]></category>
		<guid isPermaLink="false">http://blog.wonizz.tk/?p=1120</guid>

					<description><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈 입니다. 이번시간에는 리액트를 주로 사용하면서 봐왔던 state와 props에 대해서 정리를 해보려고 합니다. 아시다시피 처음 React를 공부하게 되면 제일 처음 배우게 되는 개념이지만, 필자 같은 경우 바로 소스 개발을 들어가다 보니 정확하게 개념을 인지하지 못하고, 바로 실전으로 보면서 익히게 되었습니다. 그래서 이번기회에 이 개념에 대해서 정확하게 정리를 해보는 시간을 갖겠습니다. 지난 글들은&#8230;&#160;</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/">[Reactjs] 리액트 정리 3편 : state &#038; props</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
안녕하세요?  정리하는 개발자 워니즈 입니다. 이번시간에는 리액트를 주로 사용하면서 봐왔던 <code>state</code>와 <code>props</code>에 대해서 정리를 해보려고 합니다. 아시다시피 처음 React를 공부하게 되면 제일 처음 배우게 되는 개념이지만, 필자 같은 경우 바로 소스 개발을 들어가다 보니 정확하게 개념을 인지하지 못하고, 바로 실전으로 보면서 익히게 되었습니다.

그래서 이번기회에 이 개념에 대해서 정확하게 정리를 해보는 시간을 갖겠습니다.

지난 글들은 아래를 참고 해주시면 됩니다.

<ul>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/06/reactjs-redux-project/">리액트 정리 1편 : redux project 소개(1)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/">리액트 정리 2편 : redux project 소개(2)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/">리액트 정리 3편 : state &#038; props</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/">리액트 정리 4편 : S3 웹호스팅</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/">리액트 정리 5편 : 소스 배포 &#8211; github actions </a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/21/lambda-edge-guide/">리액트 정리 6편 : 람다 이미지 리사이징</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">리액트 정리 7편 : CDN 적용</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">리액트 정리 8편 : 도메인 연결</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/16/reactjs-build-and-deploy/">리액트 정리 9편 : Codepipline을 통한 배포</a></li>
</ul>

<img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/04/react_props_1.png?w=1200&#038;ssl=1" alt="Reactjs 리액트 정리 3편 : state &#038; props" />

<h2>1. Props란 무엇인가요?</h2>

사실 Props라는 이름에서도 유추가 되듯이, Properties라는 의미를 함축하고 있습니다. 어떤 속성값을 이야기하는 것이라고 생각하시면 됩니다.

<ul>
<li>Props는 자식 컴포넌트로 전달됩니다.</li>
</ul>

Props는 자식 컴포넌트에게 전달이 됩니다. 아래 예제에서 보이듯이, <code>Welcome</code> 컴포넌트에게 <code>name</code>의 props값을 전달하였고, 그것이 노출되고 있습니다.

<pre><code class="line-numbers">class Welcome extends React.Component {
  render() {
    return <h1>Hello {this.props.name}</h1>;
  }
}
const element = <Welcome name="Sara" />;
</code></pre>

쉽게 이야기하면, 자바스크립트 <code>function</code>에서 파라미터라고 생각하면 됩니다.

<pre><code class="line-numbers">function Welcome(props) {
  return <h1>Hello {props.name}</h1>;
}
</code></pre>

이러한 Props에는 Default 값을 지정할 수 있습니다. 아래와 같이 특정 값이 지정이 되지 않으면, defaultProps의 값이 셋팅이 되면서, 화면에 노출이 됩니다.

<pre><code class="line-numbers">class Welcome extends React.Component {
  render() {
    return <h1>Hello {this.props.name}</h1>;
  }
}
Welcome.defaultProps = {
  name: "world",
};
</code></pre>

<ul>
<li>props는 변경이 되지 않습니다.</li>
</ul>

props는 immutable 하다고 말합니다. 즉, 변경이 일어나지 않기때문에 불변하다고 할 수 있습니다. Props는 하위 컴포넌트로 전달이 되기 떄문에, 변경을 할수가 없고, 오로지 redering하는 컴포넌트에서는 이 props를 가져다가 사용합니다.

<h2>2. State란 무엇인가요?</h2>

State같은 경우 그 이름에서 나타나듯이 상태를 의미합니다. Props와 마찬가지로 State역시 컴포넌트에 관한 정보를 갖고 있습니다. 그러나, 정보의 종류와 그것이 다뤄지는 방식에서 차이가 있습니다.

<ul>
<li>그럼 언제 State를 사용하는 것인가요?</li>
</ul>

컴포넌트 자체적으로 액션이 가해져서 렌더링에 변화를 줄 때, state를 사용합니다. 아래에서 보시면, 실질적으로 reder()함수에서 화면을 노출 시켜주고 있습니다.

Button 클릭에 따라, 몇번을 클릭했는지를 보여주는 Component 입니다.

<ol>
<li>버튼을 클릭하게되면, updateCount 함수를 호출합니다.</li>
<li>이전 상태(prevState의 count값)에서 +1 을 수행합니다.</li>
<li>해당 값을 state로 지정합니다.(setState)</li>
<li>업데이트 된 상태를 다시 렌더링 합니다.(render)</li>
</ol>

<pre><code class="line-numbers">class Button extends React.Component {
  constructor() {
    super();
    this.state = {
      count: 0,
    };
  }
updateCount() {
    this.setState((prevState, props) => {
      return { count: prevState.count + 1 }
    });
  }
render() {
    return (<button
              onClick={() => this.updateCount()}
            >
              Clicked {this.state.count} times
            </button>);
  }
}
</code></pre>

<ul>
<li>상태는 컴포넌트 내에서 생성이 됩니다.</li>
</ul>

<pre><code class="line-numbers">constructor() {
  super();
  this.state = {
    count: 0,
  };
}
</code></pre>

컴포넌트가 초기에 생성이 되면서, constructor함수를 호출합니다. 이 함수내에서 컴포넌트에 대한 초기 상태값을 지정할 수 있습니다.

<ul>
<li>상태는 변경이 가능합니다.</li>
</ul>

<pre><code class="line-numbers">updateCount() {
  this.setState((prevState, props) => {
    return { count: prevState.count + 1 }
  });
}
</code></pre>

위에서 보신것처럼, 컴포넌트에 대한 액션을 통해서 상태값 변경이 가능했습니다. state의 값은 property로 접근해서 직접 변경하면 안 되고, 반드시  setState()를 통해 변경이 되어야 합니다.

<h2>3. 마치며..</h2>

props와 state는 reactjs에서 가장 기본이 되는 개념입니다. reactjs를 통해서 상태에 따라 render해주는 부분이 시시각각 바뀌게 되는 것인데, 매번 상태를 변경하는 코드를 집접 넣어줘야되고, 그 상태를 render해주는 코드를 다시금 붙여주고 하는 부분이 상당히 귀찮아졌습니다.

그렇게 해서 reactjs에 redux인 상태관리 개념을 도입하게 된 것입니다. redux는 reactjs를 떠나 독립된 라이브러리 이며, 상태관리를 해주는 도구라고 생각하시면 됩니다. reactjs 본연의 view 라이브러리와 상태 관리를 해주는 redux가 만나 생산성 있는 어플리케이션 개발을 진행할 수 있습니다.

다음 이시간에는 redux 본연의 개념에 대해서 좀더 심도 깊게 정리를 해보도록 하겠습니다.

[출처]

<a class="wp-editor-md-post-content-link" href="https://medium.com/@itIsMadhavan/reactjs-props-vs-state-ff3a7680930d" target="_blank" rel="noopener">itIsMadhavan, reactjs-props-vs-state</a>

[wonism, Props와 State](
<h2 class="wp-block-heading">함께 보면 좋은 글</h2>
<ul class="wp-block-list"><li><a href="https://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/">[Reactjs] 리액트 정리 2편 : redux project 소개(2)</a></li><li><a href="https://blog.wonizz.com/2020/01/06/reactjs-redux-project/">[Reactjs] 리액트 정리 1편 : redux project 소개(1)</a></li><li><a href="https://blog.wonizz.com/2020/05/19/reactjs-build-and-deploy/">[Reactjs]  AWS Codepipeline을 통한 배포</a></li><li><a href="https://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">[Reactjs] AWS Route53을 통한 도메인 연결</a></li></ul>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/">[Reactjs] 리액트 정리 3편 : state &#038; props</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1120</post-id>	</item>
		<item>
		<title>[Reactjs] 리액트 정리 2편 : redux project 소개(2)</title>
		<link>https://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/</link>
					<comments>https://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/#respond</comments>
		
		<dc:creator><![CDATA[워니]]></dc:creator>
		<pubDate>Thu, 26 Mar 2020 07:57:07 +0000</pubDate>
				<category><![CDATA[React.js]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tech]]></category>
		<guid isPermaLink="false">http://blog.wonizz.tk/?p=1109</guid>

					<description><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 이번시간에는 지난시간에 이어 리액트 리덕스에 대한 정리 2편을 포스팅 하고자합니다. 필자는 지난 2년간 시스템 엔지니어로서 활동을 했었습니다. 애초에 시작을 스크립트 언어를 주로 다루다보니 자연스레 Front-end에 관심을 많이 갖게 되었었는데, 최근들어 리액트를 활용하여 어플리케이션 개발을 진행하다 보니, 이것저것 심화해서 공부를 진행하고 있습니다. 지난 글들은 아래를 참고 해주시면 됩니다. 리액트 정리 1편 :&#8230;&#160;</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/">[Reactjs] 리액트 정리 2편 : redux project 소개(2)</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 이번시간에는 지난시간에 이어 리액트 리덕스에 대한 정리 2편을 포스팅 하고자합니다. 필자는 지난 2년간 시스템 엔지니어로서 활동을 했었습니다. 애초에 시작을 스크립트 언어를 주로 다루다보니 자연스레 <code>Front-end</code>에 관심을 많이 갖게 되었었는데, 최근들어 리액트를 활용하여 어플리케이션 개발을 진행하다 보니, 이것저것 심화해서 공부를 진행하고 있습니다.</p>
<p>지난 글들은 아래를 참고 해주시면 됩니다.</p>
<ul>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/06/reactjs-redux-project/">리액트 정리 1편 : redux project 소개(1)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/">리액트 정리 2편 : redux project 소개(2)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/">리액트 정리 3편 : state &#038; props</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/">리액트 정리 4편 : S3 웹호스팅</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/">리액트 정리 5편 : 소스 배포 &#8211; github actions </a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/21/lambda-edge-guide/">리액트 정리 6편 : 람다 이미지 리사이징</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">리액트 정리 7편 : CDN 적용</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">리액트 정리 8편 : 도메인 연결</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/16/reactjs-build-and-deploy/">리액트 정리 9편 : Codepipline을 통한 배포</a></li>
</ul>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/03/react_redux_1.png?w=1200&#038;ssl=1" alt="Reactjs 리액트 정리 2편 : redux project 소개(2) 설명 이미지 1" /></p>
<p>리덕스는 사실 단독으로 사용하는 라이브러리 입니다. 어플리케이션의 상태관리를 도와주는 도구인데요. 제가 생각하는 리덕스는 마치 어플리케이션의 상태를 DB화 시켜서 한공간에서 관리를 해주고 어플리케이션은 그 저장정보에 따라 동적으로 움직이도록 해주는 것 같습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/03/react_redux_2.png?w=1200&#038;ssl=1" alt="Reactjs 리액트 정리 2편 : redux project 소개(2) 설명 이미지 2" /></p>
<p>필자는 사실 어떻게 보면&#8230; react와 redux의 용어 조차 혼동하고 있었습니다. 리액트는 View에 대한 Component를 제작하여 프론트엔드를 구성할 수 있는 라이브러리이고, 리덕스는 위에서 말한대로 상태를 관리하는 라이브러리 입니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/03/react_redux_5.png?w=1200&#038;ssl=1" alt="Reactjs 리액트 정리 2편 : redux project 소개(2) 설명 이미지 3" /></p>
<p>저를 잘 아는지는 모르지만&#8230;.그래도 워니즈님이라면 충분히 잘하신다는 이말이 큰 용기가 되어 열심히 공부해보기로했다.</p>
<p>이두가지를 혼합해서 사용할때 하나의 어플리케이션이 컴포넌트 기반하에 생산성있게 개발을 진행할 수 있습니다.</p>
<h2>1. 어플리케이션 개요</h2>
<p><a class="wp-editor-md-post-content-link" href="https://github.com/wonizz/productmoor-frontend" target="_blank" rel="noopener">Wonizz Repository : React Redux 어플리케이션 개발</a></p>
<p>먼저, 리덕스를 통한 컴퍼넌트를 제작할때, 어떻게 컴포넌트를 나누고, 개발을 할지 정해야합니다. 필자 같은 경우는 다음과 같은 방식으로 컴포넌트를 나누었고 그에 맞춰서 개발을 진행했습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/03/react_redux_3.png?w=1200&#038;ssl=1" alt="Reactjs 리액트 정리 2편 : redux project 소개(2) 설명 이미지 4" /></p>
<p>Header/Footer 사이에 Home component를 제작했고, 그 안에는 Category와 MainView 컴포넌트를 하위로 넣었습니다. 사실 Detail Page가 따로 있기는 하지만, 마치 SPA(Single Page Application) 처럼 동작하는 어플리케이션이라 따로 Detail Page가 있는것은 아니고, 클릭시에 우측으로 노출되도록 해두었습니다.</p>
<h2>2. 상태 관리 방법</h2>
<p>리덕스는 <code>state</code>라고 하는 객체를 갖고 있는데, 여기에다가 계속해서 어플리케이션에 관련된 모든 상태들을 담고 있는 객체형태의 오브젝트입니다. 즉, json형태로 state를 관리하고 어플리케이션에서 어떠한 동작이 발생했을 때, 이 상태를 변경하게 되면, 그 상태를 지속적으로 <code>subscribe</code> 하고있는 컴포넌트들이 자신의 어플리케이션에 상태를 반영함으로써 UI가 변경되는 원리입니다.</p>
<p>필자는 위에서 이야기했듯이 이 state라는 오브젝트가 마치 DB 처럼 사용되어 데이터를 바꾸게 되면 바뀐대로 반영이 되는 것으로 생각하고 있습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/03/react_redux_4.png?w=1200&#038;ssl=1" alt="Reactjs 리액트 정리 2편 : redux project 소개(2) 설명 이미지 5" /></p>
<p>그림에 설명이 없으니, 다음의 블로그를 참고 부탁드립니다.</p>
<p><a class="wp-editor-md-post-content-link" href="https://bestalign.github.io/2015/10/26/cartoon-intro-to-redux/" target="_blank" rel="noopener">Redux로의 카툰 안내서</a></p>
<p>1 &#8211; 3 . 사용자 액션이 발생을 하게 되면, 해당 액션에 대한 액션 정의서를 작성하여 리듀서로 보냅니다.</p>
<p>4 &#8211; 6. 리듀서는 액션의 내용을 파악하고 기존의 상태를 복사한다음에 요청온 액션의 내용을 상태에 반영하여 최종적인 상태를 스토어쪽으로 보냅니다.</p>
<p>7 &#8211; 9. connect되어있는 컨테이너 컴포넌트(위의 예시에서는 Home)가, 하위의 View 컨포넌트(Category, MainView)에게 상태가 변경되었다고 알리고, 반영을 합니다.</p>
<h2>3. 샘플 코드</h2>
<p>페이지가 최초에 로드가 될떄, 데이터를 불러오 이 데이터를 state에 반영하고 컴포넌트에서 해당 상태로 변경을 하는 예시를 코드로 정리해보겠습니다.</p>
<pre><code class="line-numbers">

src >  index.js
ReactDOM.render((
  <Provider store={store}>
    <Router history={hashHistory}>
      <Route path="/" component={App}>
        <IndexRoute component={Home} />
      </Route>
    </Router>
  </Provider>
), document.getElementById('root'));
</code></pre>
<p>제일 기초가 되는 index.js에서 Route 설정을 해둔 상태입니다. 보시면 <code>/</code> 로 접속을 하게 될 때, App + Home 컴포넌트가 호출이 됩니다.</p>
<p>App 같은 경우는 공통적으로 가져가는 Home + Footer 컴포넌트가 불려지는 컴포넌트입니다.<br />
Home 컴포넌트에서는 위에 이야기한대로 Category + MainView가 호출이 되는데, 여기서 주용한것은 리스팅이 노출되는 MainView Component입니다.</p>
<pre><code class="line-numbers">

src > components > Home > index.js

//컴포넌트가 실제 마운트 되고 나면, 리스팅할 데이터를 불러 옵니다.
  componentWillMount() {
    const tab = this.props.token ? 'feed' : 'all';
    const articlesPromise = this.props.token ?
      agent.Articles.feed :
      agent.Articles.all;
    this.props.onLoad(tab, articlesPromise, Promise.all([articlesPromise()]));
  }

//onLoad 함수가 불려지면, 상태를 변경하기위해 reducer로 dispatch 합니다.
const mapDispatchToProps = dispatch => ({
  onLoad: (tab, pager, payload) =>
    dispatch({ type: HOME_PAGE_LOADED, tab, pager, payload }),
});
</code></pre>
<p>그러면, <code>HOME_PAGE_LOADED</code> 라는 액션 타입으로 호출이 되고, reducer에서는 여기에 매칭이 되는 상태 변경 영역으로 가서 변경작업을 수행합니다.</p>
<pre><code class="line-numbers">

src > reducers > articleList.js
//리듀서는 보통 case문으로 매칭이 되는 액션타입에서 상태변경을 수행하도록 코드를 작성합니다.
//onLoad시에 request를 통해 가져온 데이터를 articles 객체에 담고 있습니다. 
case HOME_PAGE_LOADED:
      return {
        ...state,
        pager: action.pager,
        detail: '',
        articles: action.payload[0] ? action.payload[0].hits.hits : action.payload.hits.hits,
        currentPage: 0,
        tab: action.tab,
        size: 10,
        from: 0,
      };
</code></pre>
<p>이러한 상태는 모두 리덕스에서는 <code>mapStateToProps</code> 에 의해서 props로 변경이 되고, 컴포넌트에서는 이 props를 통해 접근이 가능합니다.</p>
<pre><code class="line-numbers">

src > components > Home > MainView.js
//props에는 위에서 상태 변경한 articles가 담겨있기 때문에, article를 가져와서 map을 통해 리스팅을 그려줍니다.

props.articles.map((article, index) => {
          const handleClick = ev => {
            ev.preventDefault();
            props.onClickDetail(agent.Articles.byTitle(article._source.product_title));
          };
          return (
            <Link to={''} className="img-cell" onClick={handleClick}>
              <figure>
                <img src={article._source.image_crawling} alt="Reactjs 리액트 정리 2편 : redux project 소개(2) 설명 이미지 6" />
                <figcaption></figcaption>
              </figure>
            </Link>
          );
        })
</code></pre>
<p>이렇게 해서 MainView에 데이터를 가져와 리스팅을 했습니다.</p>
<h2>4. 마치며..</h2>
<p>리액트 + 리덕스를 처음 사용할때는 도저히 무슨 이야기인지, 데이터 흐름은  어떻게 되는지 이걸통해 개발을 어떻게 하는지 막막하기만 했습니다. Jquery에 너무 익숙해져있었고, DOM을 직접 제어 하다보니 컴포넌트에 대한 이해도 없었습니다. 즉각적으로 보이는데만 수정하고 하다보니 브라우저에서 css 리스케치를 할때도 비효율적이란 것을 몰랐습니다.</p>
<p>왜 Front-end가 React 혹은 View로 넘어가는지는 아주 조금 이해가 된 것 같습니다. 컴포넌트 기반으로 어플리케이션을 작성하다보니, 필요한 부분만 상태변경을 하고 바로바로 바꿔서 보여주다보니 브라우징 속도도 굉장히 빠른것 같습니다.</p>
<p>더군다나, 개발 속도가 붙기 시작했습니다. 데이터 흐름이 어떻게 되는지 이해를 하다보니 다음에는 어떻게 개발을 해야되고 어떤식으로 수정을 해야되는지 감이 잡히기 시작했습니다.</p>
<p>아직은 허접하기 그지 없지만, 조금씩 익숙해지면서 마치 레고를 조립하듯 개발을 하다보니 뿌듯합니다. 다음이시간에는 리액트에서 사용한 라이브러리들을 정리해보겠습니다.</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/">[Reactjs] 리액트 정리 2편 : redux project 소개(2)</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1109</post-id>	</item>
		<item>
		<title>[Reactjs] github actions로 S3 웹호스팅 배포하기</title>
		<link>https://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/</link>
					<comments>https://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/#respond</comments>
		
		<dc:creator><![CDATA[워니]]></dc:creator>
		<pubDate>Wed, 08 Jan 2020 05:44:46 +0000</pubDate>
				<category><![CDATA[React.js]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tech]]></category>
		<guid isPermaLink="false">http://blog.wonizz.tk/?p=990</guid>

					<description><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 개인 플젝으로 Reactjs를 개발하고 있던 중에 AWS에 Serverless로 배포를 하려면 어떻게 해야하는지 열심히 찾아보았습니다. 그러던중 리액트 소스를 빌드하여 나온결과물을 S3에 올려서 호스팅 하면된다는 것을 알게 되었습니다. 지난 글들은 아래를 참고 해주시면 됩니다. 리액트 정리 1편 : redux project 소개(1) 리액트 정리 2편 : redux project 소개(2) 리액트 정리 3편 : state&#8230;&#160;</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/">[Reactjs] github actions로 S3 웹호스팅 배포하기</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈입니다. 개인 플젝으로 <code>Reactjs</code>를 개발하고 있던 중에 AWS에 <code>Serverless</code>로 배포를 하려면 어떻게 해야하는지 열심히 찾아보았습니다. 그러던중 리액트 소스를 빌드하여 나온결과물을 S3에 올려서 호스팅 하면된다는 것을 알게 되었습니다.</p>
<p>지난 글들은 아래를 참고 해주시면 됩니다.</p>
<ul>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/06/reactjs-redux-project/">리액트 정리 1편 : redux project 소개(1)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/">리액트 정리 2편 : redux project 소개(2)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/">리액트 정리 3편 : state &#038; props</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/">리액트 정리 4편 : S3 웹호스팅</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/">리액트 정리 5편 : 소스 배포 &#8211; github actions </a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/21/lambda-edge-guide/">리액트 정리 6편 : 람다 이미지 리사이징</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">리액트 정리 7편 : CDN 적용</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">리액트 정리 8편 : 도메인 연결</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/16/reactjs-build-and-deploy/">리액트 정리 9편 : Codepipline을 통한 배포</a></li>
</ul>
<p>빌드 배포하기에 앞서 CI/CD를 어떤것으로 정할지 고민하던차에 <code>github actions</code>라는 것을 알게 되었습니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/01/github_main_1.png?w=1200&#038;ssl=1" alt="Reactjs github actions로 S3 웹호스팅 배포하기 설명 이미지 1" /></p>
<p><a href="https://github.blog/2019-08-08-github-actions-now-supports-ci-cd/" target="_blank" rel="noopener">깃헙 액션 소개 자료</a></p>
<p>githu에서 제공하는 repository에 대하여 무료 CI/CD를 제공해준다는 내용이 가장 눈에 띕니다. 또한 yaml 파일로 직접 w/f를 작성하고 로그에 대한 이력도 볼 수 있어 매우 편리합니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/github.blog/wp-content/uploads/2019/08/streaming.gif?w=1200&#038;ssl=1" alt="Reactjs github actions로 S3 웹호스팅 배포하기 설명 이미지 2" /></p>
<p>필자도 이번 <code>react project</code>를 통해서 사용해보기로 했습니다.  yaml 파일만 짜두면 빌드/배포를 동시에 진행해주니 이보다 편할 수가 없을것 같았습니다.</p>
<h1>1. S3 웹호스팅 준비</h1>
<p>S3로 소스를 빌드하여 배포하기 위해서는 S3가 사전에 준비되어있어야 합니다. 그리고 설정도 되어있어야 합니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/01/github_main_2.png?w=1200&#038;ssl=1" alt="Reactjs github actions로 S3 웹호스팅 배포하기 설명 이미지 3" /></p>
<p>AWS console에서 S3 메뉴로 이동한 뒤, <code>버킷 만들기</code>를 선택하여 위와 같은 화면이 노출되면, 버킷 이름을 입력하고 <code>다음</code>을 클릭합니다.</p>
<ul>
<li>속성 > 정적 웹 사이트 호스팅 설정</li>
</ul>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/01/github_main_3.png?w=1200&#038;ssl=1" alt="Reactjs github actions로 S3 웹호스팅 배포하기 설명 이미지 4" /></p>
<ul>
<li>권한 > 퍼블릭 액세스 차단 해제</li>
</ul>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/01/github_main_4.png?w=1200&#038;ssl=1" alt="Reactjs github actions로 S3 웹호스팅 배포하기 설명 이미지 5" /></p>
<p>위의 설정이 완료되면, 웹호스팅 + 퍼블릭 액세스 허용 수준이 됩니다 .</p>
<ul>
<li>권한 > 버킷 정책</li>
</ul>
<p>버킷에 있는 모든 Object들에 관해서 public 허용을 해주기 위해서는 다음의 권한 작업이 필요합니다.</p>
<pre><code class="line-numbers">{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadForGetBucketObjects",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::{버킷 이름}/*"
        }
    ]
}
</code></pre>
<h1>2. github actions yaml 파일</h1>
<p>github을 통해서 S3로 배포하기 위해서는 settings > secrets 탭에 다음과 같이 입력을 해야됩니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/01/github_main_6.png?w=1200&#038;ssl=1" alt="Reactjs github actions로 S3 웹호스팅 배포하기 설명 이미지 6" /></p>
<p>허용된 권한을 갖고 잇는 user의 IAM의 id, key를 미리 입력해둡니다. create버튼을 통해서 Name와 Value형태로 입력가능하고 현재 위의 화면에서는 Value는 보이지 않습니다.</p>
<p>github에 접속하여 project에 들어가게 되면, Actions라는 탭이 보입니다. 클릭을 하여 Create New workflow를 선택하게 되면 다음과 같은 화면이 노출됩니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/01/github_main_5.png?w=1200&#038;ssl=1" alt="Reactjs github actions로 S3 웹호스팅 배포하기 설명 이미지 7" /></p>
<p>Yaml 형식으로 CI/CD를 작성하는 내용인데, 필자는 아래와 같이 입력했습니다.</p>
<pre><code class="line-numbers">name: React build
on: 
  push:                               # master Branch에서 push 이벤트가 일어났을 때만 실행
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-18.04
    steps:
      - name: Checkout source code.   # 레포지토리 체크아웃
        uses: actions/checkout@master

      - name: Cache node modules      # node modules 캐싱
        uses: actions/cache@v1
        with:
          path: node_modules
          key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.OS }}-build-
            ${{ runner.OS }}-
      - name: Install Dependencies    # 의존 파일 설치
        run: npm install

      - name: Build                   # React Build
        run: npm run-script build

      - name: Deploy                  # S3에 배포하기
        env:
          AWS_ACCESS_KEY_ID: '${{ secrets.AWS_ACCESS_KEY_ID }}'
          AWS_SECRET_ACCESS_KEY: '${{ secrets.AWS_SECRET_ACCESS_KEY }}'
        run: |
          aws s3 cp \
            --recursive \
            --region ap-northeast-2 \
            build s3://test-github # 자신의 레포지토리로 변경해주세요.
</code></pre>
<ul>
<li>소스 푸시 시 빌드</li>
</ul>
<pre><code class="line-numbers">name: React build
on: 
  push:                               # master Branch에서 push 이벤트가 일어났을 때만 실행
    branches:
      - master
</code></pre>
<ul>
<li>node_modules 캐싱</li>
</ul>
<pre><code class="line-numbers">- name: Cache node modules      # node modules 캐싱
        uses: actions/cache@v1
        with:
          path: node_modules
          key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.OS }}-build-
            ${{ runner.OS }}-
</code></pre>
<ul>
<li>Deploy</li>
</ul>
<pre><code class="line-numbers"> aws s3 cp \
            --recursive \
            --region ap-northeast-2 \
            build s3://test-github # 자신의 레포지토리로 변경해주세요.
</code></pre>
<p>배포를 하게되면, 소스가 아래와 같이 올라가게 됩니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/01/github_main_7.png?w=1200&#038;ssl=1" alt="Reactjs github actions로 S3 웹호스팅 배포하기 설명 이미지 8" /></p>
<h1>3. 마치며&#8230;</h1>
<p>이번시간에는 github actions를 통해서 S3에 react소스를 빌드 / 배포 해보는 내용을 정리해봤습니다. 최근들어 reactjs에 흥미가 생겨 재밌게 개발을 진행하고 있습니다. 또한, s3로 호스팅까지 해보니 정말 개발하는 재미가 더하는것 같습니다.</p>
<p>다음시간에는 계속에서 Reactjs 프로젝트를 어떻게 진행하고 어떤방식으로 소스를 정리해 나가는지에 대해서 다시금 포스팅 해보도록 하겠습니다.</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/">[Reactjs] github actions로 S3 웹호스팅 배포하기</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">990</post-id>	</item>
		<item>
		<title>[Reactjs] 리액트 정리 1편 : redux project 소개(1)</title>
		<link>https://blog.wonizz.com/2020/01/06/reactjs-redux-project/</link>
					<comments>https://blog.wonizz.com/2020/01/06/reactjs-redux-project/#respond</comments>
		
		<dc:creator><![CDATA[워니]]></dc:creator>
		<pubDate>Mon, 06 Jan 2020 00:49:05 +0000</pubDate>
				<category><![CDATA[React.js]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tech]]></category>
		<guid isPermaLink="false">http://blog.wonizz.tk/?p=974</guid>

					<description><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈 입니다. 필자가 초년 개발자 시절에는 프론트엔드를 주로했었습니다. 프론트엔드라곤 하지만 운영프로젝트에 소속이 되어서 자바스크립트 를 활용하여 소소하게 기능 수정을 하는 수준이였습니다. 그러던 중, reactjs 라는 것을 알게되었고 17년 4월즈음에는 5일짜리 교육도 다녀왔었습니다. 리액트 js의 가장 기초적인 부분을 배웠지만, 기존에 개발하던 방식과는 사뭇 달랐습니다. 콤포넌트들을 만들어두고 그것을 마치 레고 블록 조립하듯이 화면을 개발해가는&#8230;&#160;</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/01/06/reactjs-redux-project/">[Reactjs] 리액트 정리 1편 : redux project 소개(1)</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The standard Lorem Ipsum passage, used since the 1500s<br />
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<p>1914 translation by H. Rackham<br />
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<p>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC<br />
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<p>1914 translation by H. Rackham<br />
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
<p>안녕하세요? 정리하는 개발자 워니즈 입니다. 필자가 초년 개발자 시절에는 프론트엔드를 주로했었습니다. 프론트엔드라곤 하지만 운영프로젝트에 소속이 되어서 <code>자바스크립트</code> 를 활용하여 소소하게 기능 수정을 하는 수준이였습니다.</p>
<p>그러던 중, reactjs 라는 것을 알게되었고 17년 4월즈음에는 5일짜리 교육도 다녀왔었습니다. 리액트 js의 가장 기초적인 부분을 배웠지만, 기존에 개발하던 방식과는 사뭇 달랐습니다.</p>
<p><code>콤포넌트</code>들을 만들어두고 그것을 마치 레고 블록 조립하듯이 화면을 개발해가는 과정이였습니다.</p>
<p>급하게나마 리액트 &amp; 리덕스를 사용해본 내용을 정리해보고자 합니다.</p>
<p>지난 글들은 아래를 참고 해주시면 됩니다.</p>
<ul>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/06/reactjs-redux-project/">리액트 정리 1편 : redux project 소개(1)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/03/26/reactjs-redux-project-2/">리액트 정리 2편 : redux project 소개(2)</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/06/reactjs-redux-project-props-state/">리액트 정리 3편 : state &#038; props</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="https://blog.wonizz.com/2020/04/13/reactjs-s3-web-hosting/">리액트 정리 4편 : S3 웹호스팅</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/01/08/reactjs-github-actions-deploy/">리액트 정리 5편 : 소스 배포 &#8211; github actions </a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/04/21/lambda-edge-guide/">리액트 정리 6편 : 람다 이미지 리사이징</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/06/reactjs-aws-cloudfront-cdn-apply/">리액트 정리 7편 : CDN 적용</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/11/reactjs-aws-route53-domain/">리액트 정리 8편 : 도메인 연결</a></li>
<li><input style="margin-right:5px" type="checkbox" class="task-list-item-checkbox" checked disabled /><a class="wp-editor-md-post-content-link" href="http://blog.wonizz.com/2020/05/16/reactjs-build-and-deploy/">리액트 정리 9편 : Codepipline을 통한 배포</a></li>
</ul>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/01/react_main_1.png?w=1200&#038;ssl=1" alt="Reactjs 리액트 정리 1편 : redux project 소개(1) 설명 이미지 1" /></p>
<h1>1. 리덕스를 사용하는 이유?</h1>
<p>리액트만 사용하면 되지 <code>리덕스</code>까지 같이 사용할 필요가 있을까? 라는 생각을 했었습니다. 그런데 요즘의 웹의 추세는 빠른 속도로 사용자에게 제공을 해주어 만족도를 높여야 합니다. 그러기 위해서는 DOM 구조의 특성을 봐야 합니다.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/01/react_main_2.png?w=1200&#038;ssl=1" alt="Reactjs 리액트 정리 1편 : redux project 소개(1) 설명 이미지 2" /></p>
<ul>
<li>왼쪽의 그림에서 보이시는 것처럼 root component에서 제일 최하위 컴포넌트까지 변화를 일으키기 위해서 거쳐가야될 수많은 컴포넌트들이 있습니다. 한개를 업데이트 하기 위해서는 비효율적인 상태 변경을 보입니다 .</li>
<li>리덕스의 가장큰 장점은 명확하게 <code>상태를 관리</code>한다는 것입니다. Store라는 객체를 사용하여 상태 저장소처럼 사용을 하고 모든 컴포넌트들은 이 Store의 변경에 따라서 자신의 컴포넌트 상태를 개별로 업데이트 합니다.</li>
</ul>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.wonizz.com/wp-content/uploads/2020/01/react_main_3.png?w=1200&#038;ssl=1" alt="Reactjs 리액트 정리 1편 : redux project 소개(1) 설명 이미지 3" /></p>
<ul>
<li>리덕스를 사용하는 또하나의 가장큰 이유는 상태 변경에 대한 <code>시간 여행</code>이 가능하다는 부분이다. 리덕스로 만들어진 앱은 모든 상태들의 변경에 대해서 내부적으로 이력관리를 하고 있습니다. 그렇기 때문에 버그를 찾는 부분에서 굉장히 수월해집니다.</li>
</ul>
<h1>2. 리덕스로 진행중인 앱 소개</h1>
<p><a class="wp-editor-md-post-content-link" href="https://github.com/wonizz/productmoor-frontend" title="wonizz github" target="_blank" rel="noopener">wonizz github</a></p>
<ul>
<li>Project Structure</li>
</ul>
<pre><code class="line-numbers">.
├── build                    # 전체 소스 빌드
├── public                   # Main HTML page and Static public assets 
├── src                      # Application source code
│   ├── components           # Global Reusable Components
│   │   └── Article          # PD page all component
│   │   └── Home             # Home page all component
│   ├── constants            # action 정의서 
│   ├── reducers             # all reducers definition
│   │   ├── createStore.js   # Create and instrument redux store
│   │   └── reducers.js      # Reducer registry and injection
│   └── agent.js             # 외부 API 연계 호출 (데이터)
│   └── index.js             # 페이지 Router 정의 
</code></pre>
<p>필자의 소스를 완벽히 공유할 순 없지만, 만들어진 소스에 대한 소개를 해보려고 합니다.</p>
<p>크게는 2개의 폴더로 보시면 됩니다 .</p>
<ul>
<li>public &#8211; Main HTML (index.html)</li>
<li>src &#8211; App source</li>
</ul>
<h1>3. 컴포넌트 구조</h1>
<ul>
<li>Component Structure</li>
</ul>
<pre><code class="line-numbers">├── src                      # Application source code
│   ├── components           # Global Reusable Components
│   │   └── Article          # PD page all component
│   │   └── Home             # Home page all component
│   │        └── index.js    # Home page default component 
│   ├── constants            # action 정의서 
│   ├── reducers             # all reducers definition
│   │   ├── createStore.js   # Create and instrument redux store
│   │   └── reducers.js      # Reducer registry and injection
│   │   └── articleList.js   # 제품 목록 노출 reducer
│   └── agent.js             # 외부 API 연계 호출 (데이터)
│   └── index.js             # 페이지 Router 정의 
</code></pre>
<p>위의 소스중에서 Router 가 정의된 index.js에 대해서 먼저 보겠습니다.</p>
<ul>
<li>Router index.js</li>
</ul>
<pre><code class="line-numbers">ReactDOM.render((
  <Provider store={store}>
    <Router history={hashHistory}>
      <Route path="/" component={App}>
        <IndexRoute component={Home} />
      </Route>
    </Router>
  </Provider>
), document.getElementById('root'));
</code></pre>
<p>웹페이지가 호출되면, <code>IndexRouter</code> 인 Home 컴포넌트가 호출이 됩니다.</p>
<ul>
<li>Home > index.js</li>
</ul>
<pre><code class="line-numbers">  componentWillMount() {
    const tab = this.props.token ? 'feed' : 'all';
    const articlesPromise = this.props.token ?
      agent.Articles.feed :
      agent.Articles.all;
    this.props.onLoad(tab, articlesPromise, Promise.all([agent.Tags.getAll(), articlesPromise()]));
  }

</code></pre>
<p>Home에서 default component 인 index.js가 호출이 될 것이고, 그중에서더 위의 부분과 같이 componentWillmount 함수가 호출되는 시점을 확인해보겠습니다.</p>
<p>Home 페이지가 노출이 될 때, Main List들이 노출이 되어야 되는데 이부분을 API를 통해서 가져오는 부분입니다. 현재는 위와 같이 <code>this.props.onLoad</code> 의 함수가 호출이 됨과 동시에 props에 있는 onLoad함수를 호출합니다.</p>
<pre><code class="line-numbers">

const mapDispatchToProps = dispatch => ({
  onClickTag: (tag, pager, payload) =>
    dispatch({ type: APPLY_TAG_FILTER, tag, pager, payload }),
  onLoad: (tab, pager, payload) =>
    dispatch({ type: HOME_PAGE_LOADED, tab, pager, payload }),
  onUnload: () =>
    dispatch({  type: HOME_PAGE_UNLOADED })
});
</code></pre>
<p>그러면 `HOME_PAGE_LOADED&#8217; 라는 타입으로 reducer에게 store를 업데이트 하도록 전달합니다.(dispatch)</p>
<ul>
<li>redcucer > articleList.js</li>
</ul>
<pre><code class="line-numbers">case HOME_PAGE_LOADED:
      return {
        ...state,
        pager: action.pager,
        tags: action.payload[0].tags,
        articles: action.payload[1].articles,
        articlesCount: action.payload[1].articlesCount,
        currentPage: 0,
        tab: action.tab
};
</code></pre>
<p>위에 보시는것처럼 <code>HOME_PAGE_LOADED</code> 타입으로 전달이 될 때, state에다가 각 객체들을 담아 둡니다.<br />
그리고나서 Home의 index.js 에서 <code>mapStateToProps</code> 를 통해서 모든 상태를 <code>props</code>로 전달합니다.</p>
<ul>
<li>ArticleList.js (view component)</li>
</ul>
<p>위에서 전달된 <code>pros</code>를 아래와 같이 viewing component에서는 그냥 노출만 하면됩니다.</p>
<pre><code class="line-numbers"><div className="row masonry-container">
{
    props.articles.map(article => {
        return (
            <ArticlePreview article={article} key={article.slug} />
        );
    })
}
</div>
</code></pre>
<h1>4. 마치며..</h1>
<p>위의 내용에서 보이시는 것처럼 한눈에 보이시나요? 리덕스의 가장큰 단점! 이라고 생각하면 <code>러닝 커브</code>가 있다는 것입니다. 개념에 대해서 완벽히 숙지하고 익히지 않으면, 내용이 다소 어려울 수 있습니다. 그런데 기본적으로 <code>reducer</code>, <code>store</code>, <code>component</code> 정도의 개념만 있으면 우선 반은 성공한거라고 생각합니다.</p>
<p><code>component</code>에서 액션이 일어나면, <code>reducer</code>에게 전달이 되고, <code>store</code>를 업데이트 한 뒤, 다시 상태변경에 대해서 <code>component</code>에서 변경을 해주면 됩니다.</p>
<p>다음시간에는 리액트 소스를 빌드 해 서, S3로 웹호스팅 해보는 방법에 대해서 올리도록 하겠습니다.</p>
<p>The post <a rel="nofollow" href="https://blog.wonizz.com/2020/01/06/reactjs-redux-project/">[Reactjs] 리액트 정리 1편 : redux project 소개(1)</a> appeared first on <a rel="nofollow" href="https://blog.wonizz.com">WONIZZ.LOG</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.wonizz.com/2020/01/06/reactjs-redux-project/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">974</post-id>	</item>
	</channel>
</rss>
