Zero To One
AWS 서버리스 사진첩 만들기 본문
목표
- 이미지가 업로드되면, 원본과 별도로 썸네일을 생성하고, 이를 별도의 버킷에 저장해야 합니다.
- 썸네일 이미지는 가로 200px의 크기를 가집니다.
- 썸네일을 저장할 별도의 버킷은 람다 함수의 환경 설정으로 구성되어야 합니다.
- 썸네일 생성이 완료되면, 메일로 해당 썸네일 URL과 함께 전송이 되어야 합니다.
- Amazon SNS를 활용합니다.
사용하는 것
- node.js
- sam
시작
1. sam init -> 1 -> 5 -> 2 -> [프로젝트 이름 입력]
> sam init
You can preselect a particular runtime or package type when using the `sam init` experience.
Call `sam init --help` to learn more.
Which template source would you like to use?
1 - AWS Quick Start Templates
2 - Custom Template Location
Choice: 1
Choose an AWS Quick Start application template
1 - Hello World Example
2 - Multi-step workflow
3 - Serverless API
4 - Scheduled task
5 - Standalone function
6 - Data processing
7 - Infrastructure event management
8 - Machine Learning
Template: 5
Which runtime would you like to use?
1 - dotnetcore3.1
2 - nodejs14.x
3 - nodejs12.x
Runtime: 2
Based on your selections, the only Package type available is Zip.
We will proceed to selecting the Package type as Zip.
Based on your selections, the only dependency manager available is npm.
We will proceed copying the template using npm.
Project name [sam-app]: image-resizer
Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment)
-----------------------
Generating application:
-----------------------
Name: image-resizer
Runtime: nodejs14.x
Architectures: x86_64
Dependency Manager: npm
Application Template: quick-start-from-scratch
Output Directory: .
Next steps can be found in the README file at ./image-resizer/README.md
Commands you can use next
=========================
[*] Create pipeline: cd image-resizer && sam pipeline init --bootstrap
[*] Test Function in the Cloud: sam sync --stack-name {stack-name} --watch
> cd image-resizer
> ls
README.md __tests__ buildspec.yml package.json src template.yaml
2. code . 을 열어 src/handlers 에 있는 hello-from-lambda.js를 다음과 같이 수정한다.
exports.helloFromLambdaHandler = async (event, context) => {
console.log(JSON.stringify(event)) //JSON.stringify로 모든 로그가 찍힐 수 있게끔 한다
return 'Hello from Lambda!';
}
3.
sam build
sam deploy --guided
Error
다음과 같은 오류를 만났다
Error: Failed to create/update the stack: image-resizer-birdnine, Waiter StackCreateComplete failed: Waiter encountered a terminal failure state: For expression "Stacks[].StackStatus" we matched expected path: "CREATE_FAILED" at least once
해결법 : IAM에 정책을 다음과 같이 넣는다.
4. 버킷으로 들어가서 다음처럼 source버킷과 destination 버킷을 만들어 준다. (이름은 딱히 상관 없음)
5. 람다에 들어가서 트리거 추가
6. 테스트 확인
s3 source 에 .jpg 파일을 넣은 후 로그 확인
CloudWatch에서 로그 보기 클릭
로그가 잘 찍히는 것을 볼 수 있다.
7. JSON.stringify로 Object로 되있는 것들을 풀어서 볼 수 있다.
혹은 람다 -> 테스트 -> 테스트 이벤트 -> 템플릿 -> s3-out으로도 확인 할 수 있다.
(꼭 이부분은 저장을 해두자)
2022-04-14T01:00:26.163Z 9b26cb93-4882-440f-a661-73df67f8171d INFO {
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "ap-northeast-2",
"eventTime": "2022-04-14T01:00:25.024Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "AMAW5L9ADIVTO"
},
"requestParameters": {
"sourceIPAddress": "116.125.64.98"
},
"responseElements": {
"x-amz-request-id": "9PYTV8S384T7PC5K",
"x-amz-id-2": "6rbNkqo0ghl4WyalgqT1djsopUcV3i2pYmu0btkcdiNGYk8myKkFUad3rCLkSszyD0MkcKHHQRggIS9z4Nad4R5r4WZDSIDSj1RY+Fh/D1o="
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "3f85787e-28ff-4412-8d97-974ba620b28e",
"bucket": {
"name": "photo-source-birdnine",
"ownerIdentity": {
"principalId": "AMAW5L9ADIVTO"
},
"arn": "arn:aws:s3:::photo-source-birdnine"
},
"object": {
"key": "sspring.jpg",
"size": 115524,
"eTag": "7c0a36cee46611337af5e6c21cab9ce5",
"sequencer": "0062577228F94E5D72"
}
}
}
]
}
8. s3 소스 버킷에 이벤트 알림도 설정되있는 것을 볼 수 있다.
9. 위 결과를 바탕으로 다음을 작성한다.
exports.helloFromLambdaHandler = async (event, context) => {
console.log(JSON.stringify(event)) //JSON.stringify로 모든 로그가 찍힐 수 있게끔 한다
const sourceBucktName = '소스버켓이름'
const uploadFileName = '업로드파일이름'
const destinationBucktName = '대상버켓이름'
// 원본 버킷으로부터 파일 읽기
const s3Object = await s3.getObject({
Bucket: sourceBucktName,
Key: uploadFileName
}).promise()
// 이미지 리사이즈, sharp 라이브러리가 필요합니다.
const data = await sharp(s3Object.Body)
.resize(200)
.jpeg({ mozjpeg: true })
.toBuffer()
// 대상 버킷으로 파일 쓰기
const result = await s3.putObject({
Bucket: destinationBucktName,
Key: uploadFileName,
ContentType: 'image/jpeg',
Body: data,
ACL: 'public-read'
}).promise()
return 'Hello from Lambda!';
}
그럼 다음과 같이 입력할 수 있다.
exports.helloFromLambdaHandler = async (event, context) => {
console.log(JSON.stringify(event)) //JSON.stringify로 모든 로그가 찍힐 수 있게끔 한다
const sourceBucktName = event.Records[0].s3.bucket.name
const uploadFileName = event.Records[0].s3.object.key
const destinationBucktName = 'photo-destination-birdnine'
console.log(sourceBucktName)
console.log(uploadFileName)
// 원본 버킷으로부터 파일 읽기
const s3Object = await s3.getObject({
Bucket: sourceBucktName,
Key: uploadFileName
}).promise()
// 이미지 리사이즈, sharp 라이브러리가 필요합니다.
const data = await sharp(s3Object.Body)
.resize(200)
.jpeg({ mozjpeg: true })
.toBuffer()
// 대상 버킷으로 파일 쓰기
const result = await s3.putObject({
Bucket: destinationBucktName,
Key: uploadFileName,
ContentType: 'image/jpeg',
Body: data,
ACL: 'public-read'
}).promise()
return 'Hello from Lambda!';
}
(중간에 console.log를 찍어서 확인도 해보자)
10. 로컬상에서 test
sam build
sam local invoke
> sam local invoke
Invoking src/handlers/hello-from-lambda.helloFromLambdaHandler (nodejs14.x)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-nodejs14.x:rapid-1.46.0-x86_64.
Mounting /home/jaehyeok/dummy/image-resizer/.aws-sam/build/helloFromLambdaFunction as /var/task:ro,delegated inside runtime container
START RequestId: 448af66d-bb3c-4e3f-ad98-f104e330e6f4 Version: $LATEST
2022-04-14T01:15:27.082Z 448af66d-bb3c-4e3f-ad98-f104e330e6f4 INFO {}
2022-04-14T01:15:27.083Z 448af66d-bb3c-4e3f-ad98-f104e330e6f4 ERROR Invoke Error {"errorType":"TypeError","errorMessage":"Cannot read property '0' of undefined","stack":["TypeError: Cannot read property '0' of undefined"," at Runtime.exports.helloFromLambdaHandler [as handler] (/var/task/src/handlers/hello-from-lambda.js:4:42)"," at Runtime.handleOnceNonStreaming (/var/runtime/Runtime.js:73:25)"]}
END RequestId: 448af66d-bb3c-4e3f-ad98-f104e330e6f4
REPORT RequestId: 448af66d-bb3c-4e3f-ad98-f104e330e6f4 Init Duration: 0.11 ms Duration: 72.35 ms Billed Duration: 73 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"errorType":"TypeError","errorMessage":"Cannot read property '0' of undefined","trace":["TypeError: Cannot read property '0' of undefined"," at Runtime.exports.helloFromLambdaHandler [as handler] (/var/task/src/handlers/hello-from-lambda.js:4:42)"," at Runtime.handleOnceNonStreaming (/var/runtime/Runtime.js:73:25)"]}%
오류가 발생했다.
sam invoke 문제로 판단.
다음과 같이 7번에 로그를 s3-put-event.json으로 파일을 하나 만들어 붙여넣기 해주자
> sam local invoke -e ./src/handlers/s3-put-event.json
Invoking src/handlers/hello-from-lambda.helloFromLambdaHandler (nodejs14.x)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-nodejs14.x:rapid-1.46.0-x86_64.
Mounting /home/jaehyeok/dummy/image-resizer/.aws-sam/build/helloFromLambdaFunction as /var/task:ro,delegated inside runtime container
START RequestId: f6a02525-0715-434f-a447-45141bf77d09 Version: $LATEST
2022-04-14T01:39:03.968Z f6a02525-0715-434f-a447-45141bf77d09 INFO {"Records":[{"eventVersion":"2.1","eventSource":"aws:s3","awsRegion":"ap-northeast-2","eventTime":"2022-04-14T01:00:25.024Z","eventName":"ObjectCreated:Put","userIdentity":{"principalId":"AMAW5L9ADIVTO"},"requestParameters":{"sourceIPAddress":"116.125.64.98"},"responseElements":{"x-amz-request-id":"9PYTV8S384T7PC5K","x-amz-id-2":"6rbNkqo0ghl4WyalgqT1djsopUcV3i2pYmu0btkcdiNGYk8myKkFUad3rCLkSszyD0MkcKHHQRggIS9z4Nad4R5r4WZDSIDSj1RY+Fh/D1o="},"s3":{"s3SchemaVersion":"1.0","configurationId":"3f85787e-28ff-4412-8d97-974ba620b28e","bucket":{"name":"photo-source-birdnine","ownerIdentity":{"principalId":"AMAW5L9ADIVTO"},"arn":"arn:aws:s3:::photo-source-birdnine"},"object":{"key":"sspring.jpg","size":115524,"eTag":"7c0a36cee46611337af5e6c21cab9ce5","sequencer":"0062577228F94E5D72"}}}]}
2022-04-14T01:39:03.969Z f6a02525-0715-434f-a447-45141bf77d09 INFO photo-source-birdnine
2022-04-14T01:39:03.969Z f6a02525-0715-434f-a447-45141bf77d09 INFO sspring.jpg
2022-04-14T01:39:03.969Z f6a02525-0715-434f-a447-45141bf77d09 ERROR Invoke Error {"errorType":"ReferenceError","errorMessage":"s3 is not defined","stack":["ReferenceError: s3 is not defined"," at Runtime.exports.helloFromLambdaHandler [as handler] (/var/task/src/handlers/hello-from-lambda.js:11:22)"," at Runtime.handleOnceNonStreaming (/var/runtime/Runtime.js:73:25)"]}
END RequestId: f6a02525-0715-434f-a447-45141bf77d09
REPORT RequestId: f6a02525-0715-434f-a447-45141bf77d09 Init Duration: 0.03 ms Duration: 65.88 ms Billed Duration: 66 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"errorType":"ReferenceError","errorMessage":"s3 is not defined","trace":["ReferenceError: s3 is not defined"," at Runtime.exports.helloFromLambdaHandler [as handler] (/var/task/src/handlers/hello-from-lambda.js:11:22)"," at Runtime.handleOnceNonStreaming (/var/runtime/Runtime.js:73:25)"]}
콘솔로그는 잘 찍혔지만 아직 에러가 난다.
s3 is not defined에러이다.
공식문서를 참고해서 aws-sdk를 설치해주고 리전설정 및 s3설정을 해주자
npm install aws-sdk
https://docs.aws.amazon.com/ko_kr/sdk-for-javascript/v2/developer-guide/installing-jssdk.html
다음과 같이 작성된다
const AWS = require('aws-sdk');
AWS.config.update({region: 'ap-northeast-2'});
const s3 = new AWS.S3({apiVersion: '2006-03-01'});
exports.helloFromLambdaHandler = async (event, context) => {
console.log(JSON.stringify(event)) //JSON.stringify로 모든 로그가 찍힐 수 있게끔 한다
const sourceBucktName = event.Records[0].s3.bucket.name
const uploadFileName = event.Records[0].s3.object.key
const destinationBucktName = 'photo-destination-birdnine'
console.log(sourceBucktName)
console.log(uploadFileName)
// 원본 버킷으로부터 파일 읽기
const s3Object = await s3.getObject({
Bucket: sourceBucktName,
Key: uploadFileName
}).promise()
// 이미지 리사이즈, sharp 라이브러리가 필요합니다.
const data = await sharp(s3Object.Body)
.resize(200)
.jpeg({ mozjpeg: true })
.toBuffer()
// 대상 버킷으로 파일 쓰기
const result = await s3.putObject({
Bucket: destinationBucktName,
Key: uploadFileName,
ContentType: 'image/jpeg',
Body: data,
ACL: 'public-read'
}).promise()
return 'Hello from Lambda!';
}
다시 빌드 후 local invoke를 실행해보자
sam build
sam local invoke -e ./src/handlers/s3-put-event.json
----------------------------------------------------------------------------------------------------------------------------------------------------------
M1 Mac을 사용하는 경우, package.json 구성을 다음과 같이 설정합니다.
"dependencies": {
"aws-sdk": "^2.1111.0"
},
"scripts": {
"preinstall": "npm install --platform=linux --arch=x64 --no-save sharp"
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
결과
> sam local invoke -e ./src/handlers/s3-put-event.json
Invoking src/handlers/hello-from-lambda.helloFromLambdaHandler (nodejs14.x)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-nodejs14.x:rapid-1.46.0-x86_64.
Mounting /home/jaehyeok/dummy/image-resizer/.aws-sam/build/helloFromLambdaFunction as /var/task:ro,delegated inside runtime container
START RequestId: 2d51a99e-f01c-4766-b69a-9c773ed1f970 Version: $LATEST
2022-04-14T02:06:45.757Z 2d51a99e-f01c-4766-b69a-9c773ed1f970 INFO {"Records":[{"eventVersion":"2.1","eventSource":"aws:s3","awsRegion":"ap-northeast-2","eventTime":"2022-04-14T01:00:25.024Z","eventName":"ObjectCreated:Put","userIdentity":{"principalId":"AMAW5L9ADIVTO"},"requestParameters":{"sourceIPAddress":"116.125.64.98"},"responseElements":{"x-amz-request-id":"9PYTV8S384T7PC5K","x-amz-id-2":"6rbNkqo0ghl4WyalgqT1djsopUcV3i2pYmu0btkcdiNGYk8myKkFUad3rCLkSszyD0MkcKHHQRggIS9z4Nad4R5r4WZDSIDSj1RY+Fh/D1o="},"s3":{"s3SchemaVersion":"1.0","configurationId":"3f85787e-28ff-4412-8d97-974ba620b28e","bucket":{"name":"photo-source-birdnine","ownerIdentity":{"principalId":"AMAW5L9ADIVTO"},"arn":"arn:aws:s3:::photo-source-birdnine"},"object":{"key":"sspring.jpg","size":115524,"eTag":"7c0a36cee46611337af5e6c21cab9ce5","sequencer":"0062577228F94E5D72"}}}]}
2022-04-14T02:06:45.759Z 2d51a99e-f01c-4766-b69a-9c773ed1f970 INFO photo-source-birdnine
2022-04-14T02:06:45.759Z 2d51a99e-f01c-4766-b69a-9c773ed1f970 INFO sspring.jpg
2022-04-14T02:06:56.094Z 2d51a99e-f01c-4766-b69a-9c773ed1f970 ERROR Invoke Error {"errorType":"ReferenceError","errorMessage":"sharp is not defined","stack":["ReferenceError: sharp is not defined"," at Runtime.exports.helloFromLambdaHandler [as handler] (/var/task/src/handlers/hello-from-lambda.js:21:18)"," at processTicksAndRejections (internal/process/task_queues.js:95:5)"]}
{"errorType":"ReferenceError","errorMessage":"sharp is not defined","trace":["ReferenceError: sharp is not defined"," at Runtime.exports.helloFromLambdaHandler [as handler] (/var/task/src/handlers/hello-from-lambda.js:21:18)"," at processTicksAndRejections (internal/process/task_queues.js:95:5)"]}END RequestId: 2d51a99e-f01c-4766-b69a-9c773ed1f970
REPORT RequestId: 2d51a99e-f01c-4766-b69a-9c773ed1f970 Init Duration: 0.10 ms Duration: 10520.20 ms Billed Duration: 10521 ms Memory Size: 128 MB Max Memory Used: 128 MB
다시 에러가 난다.
sharp 에러이다.
sharp를 설치해주고 sharp를 선언해주자
npm install sharp
Full_code
const AWS = require('aws-sdk');
AWS.config.update({region: 'ap-northeast-2'});
const s3 = new AWS.S3({apiVersion: '2006-03-01'});
const sharp = require('sharp')
exports.helloFromLambdaHandler = async (event, context) => {
console.log(JSON.stringify(event)) //JSON.stringify로 모든 로그가 찍힐 수 있게끔 한다
const sourceBucktName = event.Records[0].s3.bucket.name
const uploadFileName = event.Records[0].s3.object.key
const destinationBucktName = 'photo-destination-birdnine'
console.log(sourceBucktName)
console.log(uploadFileName)
// 원본 버킷으로부터 파일 읽기
const s3Object = await s3.getObject({
Bucket: sourceBucktName,
Key: uploadFileName
}).promise()
// 이미지 리사이즈, sharp 라이브러리가 필요합니다.
const data = await sharp(s3Object.Body)
.resize(200)
.jpeg({ mozjpeg: true })
.toBuffer()
// 대상 버킷으로 파일 쓰기
const result = await s3.putObject({
Bucket: destinationBucktName,
Key: uploadFileName,
ContentType: 'image/jpeg',
Body: data,
ACL: 'public-read'
}).promise()
return 'Hello from Lambda!';
}
에러가 생겼다. s3만 설정해주면 된다.
> sam local invoke -e ./src/handlers/s3-put-event.json
Invoking src/handlers/hello-from-lambda.helloFromLambdaHandler (nodejs14.x)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-nodejs14.x:rapid-1.46.0-x86_64.
Mounting /home/jaehyeok/dummy/image-resizer/.aws-sam/build/helloFromLambdaFunction as /var/task:ro,delegated inside runtime container
START RequestId: 99db280e-5dd1-49af-9d1a-4cce8be46be9 Version: $LATEST
2022-04-14T02:10:11.570Z 99db280e-5dd1-49af-9d1a-4cce8be46be9 INFO {"Records":[{"eventVersion":"2.1","eventSource":"aws:s3","awsRegion":"ap-northeast-2","eventTime":"2022-04-14T01:00:25.024Z","eventName":"ObjectCreated:Put","userIdentity":{"principalId":"AMAW5L9ADIVTO"},"requestParameters":{"sourceIPAddress":"116.125.64.98"},"responseElements":{"x-amz-request-id":"9PYTV8S384T7PC5K","x-amz-id-2":"6rbNkqo0ghl4WyalgqT1djsopUcV3i2pYmu0btkcdiNGYk8myKkFUad3rCLkSszyD0MkcKHHQRggIS9z4Nad4R5r4WZDSIDSj1RY+Fh/D1o="},"s3":{"s3SchemaVersion":"1.0","configurationId":"3f85787e-28ff-4412-8d97-974ba620b28e","bucket":{"name":"photo-source-birdnine","ownerIdentity":{"principalId":"AMAW5L9ADIVTO"},"arn":"arn:aws:s3:::photo-source-birdnine"},"object":{"key":"sspring.jpg","size":115524,"eTag":"7c0a36cee46611337af5e6c21cab9ce5","sequencer":"0062577228F94E5D72"}}}]}
2022-04-14T02:10:11.572Z 99db280e-5dd1-49af-9d1a-4cce8be46be9 INFO photo-source-birdnine
2022-04-14T02:10:11.572Z 99db280e-5dd1-49af-9d1a-4cce8be46be9 INFO sspring.jpg
2022-04-14T02:10:22.007Z 99db280e-5dd1-49af-9d1a-4cce8be46be9 ERROR Invoke Error {"errorType":"AccessControlListNotSupported","errorMessage":"The bucket does not allow ACLs","code":"AccessControlListNotSupported","message":"The bucket does not allow ACLs","region":null,"time":"2022-04-14T02:10:22.006Z","requestId":"TWPNHYZGZGC4YNTB","extendedRequestId":"PUABWnst+1RrA6nUp5VV+j/89vMhZi0P6UbOlgXEM0zdqjicKIgrbIrTb6iI9PasgDKC/C4Onjw=","statusCode":400,"retryable":false,"retryDelay":50.89385680957022,"stack":["AccessControlListNotSupported: The bucket does not allow ACLs"," at Request.extractError (/var/task/node_modules/aws-sdk/lib/services/s3.js:711:35)"," at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)"," at Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:78:10)"," at Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:686:14)"," at Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)"," at AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)"," at /var/task/node_modules/aws-sdk/lib/state_machine.js:26:10"," at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:38:9)"," at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:688:12)"," at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:116:18)"]}
END RequestId: 99db280e-5dd1-49af-9d1a-4cce8be46be9
REPORT RequestId: 99db280e-5dd1-49af-9d1a-4cce8be46be9 Init Duration: 0.10 ms Duration: 10666.51 ms Billed Duration: 10667 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"errorType":"AccessControlListNotSupported","errorMessage":"The bucket does not allow ACLs","trace":["AccessControlListNotSupported: The bucket does not allow ACLs"," at Request.extractError (/var/task/node_modules/aws-sdk/lib/services/s3.js:711:35)"," at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)"," at Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:78:10)"," at Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:686:14)"," at Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)"," at AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)"," at /var/task/node_modules/aws-sdk/lib/state_machine.js:26:10"," at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:38:9)"," at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:688:12)"," at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:116:18)"]}
퍼블릭 엑세스를 모두 체크박스 해제해주고,
객체 소유권 편집도 ACL 활성화 시켜주자.
결과
> sam local invoke -e ./src/handlers/s3-put-event.json
Invoking src/handlers/hello-from-lambda.helloFromLambdaHandler (nodejs14.x)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-nodejs14.x:rapid-1.46.0-x86_64.
Mounting /home/jaehyeok/dummy/image-resizer/.aws-sam/build/helloFromLambdaFunction as /var/task:ro,delegated inside runtime container
START RequestId: 2c74c4b7-adc5-4990-8759-2c04d65d4045 Version: $LATEST
2022-04-14T02:17:52.701Z 2c74c4b7-adc5-4990-8759-2c04d65d4045 INFO {"Records":[{"eventVersion":"2.1","eventSource":"aws:s3","awsRegion":"ap-northeast-2","eventTime":"2022-04-14T01:00:25.024Z","eventName":"ObjectCreated:Put","userIdentity":{"principalId":"AMAW5L9ADIVTO"},"requestParameters":{"sourceIPAddress":"116.125.64.98"},"responseElements":{"x-amz-request-id":"9PYTV8S384T7PC5K","x-amz-id-2":"6rbNkqo0ghl4WyalgqT1djsopUcV3i2pYmu0btkcdiNGYk8myKkFUad3rCLkSszyD0MkcKHHQRggIS9z4Nad4R5r4WZDSIDSj1RY+Fh/D1o="},"s3":{"s3SchemaVersion":"1.0","configurationId":"3f85787e-28ff-4412-8d97-974ba620b28e","bucket":{"name":"photo-source-birdnine","ownerIdentity":{"principalId":"AMAW5L9ADIVTO"},"arn":"arn:aws:s3:::photo-source-birdnine"},"object":{"key":"sspring.jpg","size":115524,"eTag":"7c0a36cee46611337af5e6c21cab9ce5","sequencer":"0062577228F94E5D72"}}}]}
2022-04-14T02:17:52.702Z 2c74c4b7-adc5-4990-8759-2c04d65d4045 INFO photo-source-birdnine
2022-04-14T02:17:52.702Z 2c74c4b7-adc5-4990-8759-2c04d65d4045 INFO sspring.jpg
"Hello from Lambda!"END RequestId: 2c74c4b7-adc5-4990-8759-2c04d65d4045
REPORT RequestId: 2c74c4b7-adc5-4990-8759-2c04d65d4045 Init Duration: 0.12 ms Duration: 602.14 ms Billed Duration: 603 ms Memory Size: 128 MB Max Memory Used: 128 MB
잘 뜨는 것을 볼 수 있고 버킷에 사진까지 잘 올라와져 있다.
11.
sam deploy
sam deploy --guided는 앞서 했으므로 sam deploy만 해주면 된다.
그러고나서, 앞서 만든 photo-source-birdnine 에 사진(한글,띄어쓰기 없는 jpg파일)을 업로드하면 photo-destination-birdnine 에 리사이즈 된 사진이 나온다.
만약 사진이 안올라온다면 이글 참조.
'마이크로서비스' 카테고리의 다른 글
S3, Lambda, SQS (0) | 2022.04.15 |
---|---|
AccessDenied: Access Denied 에러 해결 (0) | 2022.04.14 |
2) 마이크로서비스 정리 (0) | 2022.04.12 |
도메인 주도 설계 (코로나19 환자 관리 정보시스템 설계) (0) | 2022.04.08 |
마이크로서비스 정리 (0) | 2022.04.08 |