메모장



Available Script react


* https://github.com/seye2/reactssr



aws lambda, api gateway를 이용한 웹 서버 구축 및 배포 방법#4 aws

# 이전 글에서 만든 hello world를 apex로 alias별 람다 생성 및 배포 설정

https://github.com/seye2/serverlessWeb/tree/master/3.LambdaAlias

## 실행 방법

alias별 람다 배포

stage와 prod 두 단계로 나누어서 소스를 배포하려고한다.

stage는 테스트 혹은 QA진행 시 관리할 소스
prod는 실제 배포 후 관리할 소스이다.

'''
npm run stage
'''

alias:stage가 생성된다.


'''
npm run prod
'''

alias:prod가 생성된다.




angular2, rxjs javascript

https://owenjeon.github.io/all-archives/
Angular2, rxjs에 대해서 잘 정리되어 있다.
워느님 발끝만 봅니다.


aws lambda, api gateway를 이용한 웹 서버 구축 및 배포 방법#3 aws

구현한 내용을 apex를 이용 lambda에 올리는 것에 대해서 설명한다.

1. aws cli설치
AWS cli - download

AWS Access Key ID, AWS Secret Access Key등 정보는 아래 링크를 참조하면 된다.
 
$ aws configure
AWS Access Key ID: foo
AWS Secret Access Key: bar
Default region name [us-west-2]: us-west-2
Default output format [None]: json
2. apex 설치

1번에서 만든 hello world를 apex로 람다 생성 및 배포 설정

실행 방법

apex는 기본적으로 functions폴더 내에 있는 폴더명을 기준으로 Lambda 함수명으로 지정된다. 그리고 배포시 functions폴더 밑에 있는 폴더들을 람다로 배포한다.

그리고 project.json파일을 생성하여 { "name": "hello", "description": "Node.js example project", "role": "arn:aws:iam::448067002058:role/lambda", "memory": 512 }

위와 같이 작성한다.

name은 람다 함수명 prefix로 지정된다. description은 Lambda에 대한 설명이다. role은 Lambda가 실행될 role을 지정한다. memory는 람다가 실행하는데 필요한 메모리 지정이다.

위와 같이하여 apex deploy를 실행하면 hello_world라는 Lambda함수가 실행된다.

apex init으로 실행을 하면 IAM ROLE이 매번 생성되어 관리하기 어려운 어려움이 있다. 그래서 위와같이 functions폴더 및 project.json파일을 수동으로 생성하여 바로 apex deploy를 실행하면 role이나 policy자동 생성없이 기존롤을 지정하여 배포 및 실행 가능하다.

npm run server

npm run server실행 시 build.bat배치 파일 실행

  • build.bat
del /s /q c:\project\serverlessWeb\2.Lambda\functions\world\*                                                      #functions\world 내 파일 삭제
rmdir /s /q c:\project\serverlessWeb\2.Lambda\functions\world\node_modules                                         #node_modules 폴더 삭제
copy c:\project\serverlessWeb\2.Lambda\app.js c:\project\serverlessWeb\2.Lambda\functions\world\app.js             #app.js를 functions\world 로 복사
copy c:\project\serverlessWeb\2.Lambda\index.js c:\project\serverlessWeb\2.Lambda\functions\world\index.js         #index.js를 functions\world 로 복사
copy c:\project\serverlessWeb\2.Lambda\package.json c:\project\serverlessWeb\2.Lambda\functions\world\package.json #package.json를 functions\world 로 복사
cd c:\project\serverlessWeb\2.Lambda\functions\world
yarn && cd c:\project\serverlessWeb\2.Lambda && apex deploy                                                        #yarn으로 package.json설치 후 apex deploy로 functions\world 내 파일을 압축하여 Lambda로 배포

위의 내용을 거친 후 apex invoke world라는 함수명을 지정하여 invoke하면 원격으로 실행된 람다 함수의 결과를 로컬에서 확인 가능하다.(성공이나 실패에 관련된 메세지)


apex deploy시 아래와 같이 current버전으로 lambda가 생성된다.






aws lambda, api gateway를 이용한 웹 서버 구축 및 배포 방법#2 aws

앞서 링크를 걸었던 내용들은 lambda, apex와 api gateway등에 대한 정의 및 설정 등에 대한 내용이 정리된 내용을 공유하였다.

이번 글의 내용은 아래와 같이 진행하고자 한다.

- 예제 파일

1. node.js와 express 설정

 - app.js
var express = require('express');
var app = express();
app.get('/', function (req, res) {  	res
	.send('Hello World!');});app.listen(3000, function () {
	  	console.log('Example app listening on port 3000!');
});

2. lambda와 연결하기 위한 aws-serverless-express설정


Run serverless applications and REST APIs using your existing Node.js application framework, on top of AWS Lambda and Amazon API Gateway. The sample provided allows you to easily build serverless web applications/services and RESTful APIs using the Express framework.

Lambda와 API Gateway에 express framework를 사용하여 웹 어플리케이션/서비스 와  RESTful APIs를 쉽게 제공할 수 있다.

- app.js
var express = require('express');
var awsServerlessExpressMiddleware = require('aws-serverless-express/middleware');
var app = express();
app.use(awsServerlessExpressMiddleware.eventContext());
app.get('/', function (req, res) {
	res.send('Hello World!');
});
module.exports = app

 - index.js

// lambda.js'
use strict'
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./app');
const server = awsServerlessExpress.createServer(app);
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);



1 2 3 4 5 6 7 8 9 10 다음