LoginSignup
14
7

More than 3 years have passed since last update.

CloudFormationでLambdaのLayerを作成する

Last updated at Posted at 2019-02-05

準備

ライブラリを作成し、ディレクトリ構成は以下のようにします。

layer.zip
│ python/lib
└ python/yourlib

zipファイルにして、S3にアップロード

zip -r layer.zip python
aws s3 cp ./layer.zip s3://yourbucket

CloudFormation template sample

lambdalayer.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
#Layer作成
  LambdaLayer:
    Type: "AWS::Lambda::LayerVersion"
    Properties:
      CompatibleRuntimes: 
        - python3.6 #Valid Values: nodejs6.10 | nodejs8.10 | java8 | python2.7 | python3.6 | python3.7 | dotnetcore1.0 | dotnetcore2.0 | dotnetcore2.1 | go1.x | ruby2.5 
      Content: 
        S3Bucket: your-bucket
        S3Key: layer.zip    #Layer File
      Description: something
      LayerName: yourlayername

#LambdaSAM
  Lambda:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: lambda_function.lambda_handler
      Runtime: python3.6
      MemorySize: 128
      Timeout: 20
      Role: !Sub 'arn:aws:iam::${AWS::AccountId}:role/lambda-common-role'
      CodeUri: src/lambdasrcc/
      Layers:
        - !Ref LambdaLayer

注意

Layerのサイズ制限は以下になります。

リソース 制限
サイズ 50 MB (圧縮)
250 MB(解凍)

解凍の場合、既存ソースと合わせて250 MB以下です。

14
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
7