본문 바로가기

Compute/Lambda

(9)
Serverless Framework [환경설정] Cloud9을 이용 아래 내용에 따라 Cloud9의 Role을 적용 https://awskrug.github.io/eks-workshop/prerequisites/workspaceiam/ EKSworkshop.com In this workshop, we will explore multiple ways to configure VPC, ALB, and EC2 Kubernetes workers, and Amazon Elastic Kubernetes Service. www.eksworkshop.com 서버리스의 IAM 권한 확인 https://www.serverless.com/framework/docs/providers/aws/guide/iam Serverless Framework - AWS Lam..
AWS Lambda X-ray 및 Insight(Serverless, MSA 모니터링) 재미와 학습으로 시작했던 서버리스 MSA로 구성한 서비스가 어느새 2년이라는 시간이 지났다. 사용자도 꽤 늘어 기능을 추가하다 보니, 현재 40개가 좀 넘는 Lambda가 돌아가고 있다. (비용은 월 $150 정도) 모든 것을 AWS에 위임하여 서비스 중이더라도 장애는 발생되어(특히 외부 API들) 서버리스 MSA 모니터링을 위한 X-Ray와 Lambda Insight에 대해 간략하게 포스팅 한다. (규모가 작은 서비스지만 모니터링 체계는 크게 다르지 않을 듯 하여..) 기본적으로 CloudWatch를 통한 Lambda 모니터링은 아래와 같다. Invocations – 5분 동안 함수가 호출된 람다 횟수 기간 – 함수 코드가 이벤트를 처리하는 데 소요하는 평균, 최소 및 최대 시간 오류 수 및 성공률(%..
AWS Lambda Edge 콜드스타트? Lambda Edge(이하 LE) 도입을 위해 성능을 측정 비교는 LE를 적용한 CF와 적용하지 않은 CF의 레이턴시 및 에러률 측정 원본은 동일하게 S3로 정적이미지 URL LE의 동작은 Viwer Response에 커스텀 헤더를 추가 성능 측정은 locust로, RPS 5,000 / 인터벌 1~3초 / 커넥션 50,000 그 결과 콜드스타트 문제를 넘어 RPS가 1,000을 넘어갈 때 약 3% 이상의 503(람다 실행 초과)가 발생 반면 LE를 적용하지 않은 CF의 경우 특이사항은 발견되지 않음 사실 LE의 RPS 기본 쿼터는 1,000으로 아주 정확하게 동작하고 있는 듯 보임 https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cl..
AWS Lambda@Edge Redirect / Add Custom Header Viewer Request, Origin Request 둘 다 동작 (Viewer Req의 경우 캐싱 동작) 'use strict'; /* This is an origin request function */ exports.handler = (event, context, callback) => { /* * Generate HTTP redirect response with 301 status code and Location header based on region. */ const request = event.Records[0].cf.request; const request_uri = request.uri; const host = request.headers.host[0].value const path = ..
AWS Lambda Edge를 이용한 이미지 리사이징 먼저 기본 내용은 아래 AWS Blog를 통해 확인하자. Resizing Images with Amazon CloudFront & Lambda@Edge | AWS CDN Blog | Amazon Web Services Do you have lots of images that need to be modified before delivery? No problem with Amazon CloudFront and Lambda@Edge. Read more on how you can use our services to modify image dimensions, apply watermarks, or optimize formats based on browser support all aws.amazon.com 중요 키..
AWS Lambda 활용 태깅 없는 EC2 Instance 정지 Sample Code(Python boto3) import boto3 def lambda_handler(event, context): no_tag_instances = [] ec2 = boto3.client('ec2') instances = [i for i in boto3.resource('ec2', region_name='ap-northeast-2').instances.all()] # Print instance_id of instances that do not have a Tag of Key='Foo' for i in instances: if i.tags is None: no_tag_instances.append(i.instance_id); response = ec2.stop_instances( Ins..
AWS Lambda 활용 EIP 변경 방화벽 문제 등이나 기타 이유로 Elastic IP를 사용하는 서비스를 운영할 때 SPOF 발생 (과거 NAT Gateway가 생기기 전에 NAT Instance 단일 장애 지점 문제와 같은...ELB는 아직 EIP를 지원하지 않음) 1. 필요한 Policy { "Version": "2012-10-17", "Statement": [ { "Sid": "Stmt1491964068000", "Effect": "Allow", "Action": [ "ec2:AssociateAddress", "ec2:DescribeAddresses" ], "Resource": [ "*" ] } ] } 2. Role 생성(Trust relationsships) { "Version": "2012-10-17", "Statement": ..
AWS Lambda를 이용하여 Security Group 자동 제어 이번 블로그는 AWS의 How to Automatically Update Your Security Group .. AWS Lambda 블로깅 테스트 후기? 참고 How to Automatically Update Your Security Groups for Amazon CloudFront and AWS WAF by Using AWS Lambda | Amazon Web Services Update on June 14, 2018: We removed an out-of-date code sample. Update on August 23, 2018: We revised the “Configure your Lambda function’s trigger” procedure. Amazon CloudFront can h..
AWS Lambda를 이용하여 S3 업로드된 파일 meta-data 변경 오늘은 Lambda에 관련 포스팅 Lambda를 이용하여 S3 업로드 시에 파일의 meta-data(헤더)를 변경해보도록 하겠음. meta-data를 통해 client가 vod(mp4) 파일을 스트리밍할 지, 강제로 다운로드 받을지 결정할 수 있음. App 서버에서 Client가 업로드 시 meta-data 수정 전/후 파일을 S3에 업로드 할 수 있지만, Lambda 학습할 겸 테스트 해봄. 1.Overview Lambda는 AWS의 event trigger function 서비스입니다. S3 / SNS 등에서 Event가 발생되면 Lambda에 호출을 하고 Lambda는 node / python / java 등을 이용하여 작업을 함. Lambda와 S3를 연동해서 썸네일, 파일의 메타 데이터 변경이 ..