Suppose I want to upload MaxMind GeoIp city database to AWS, and make it as Lambda layer.

  1. Create a zip file with below structure

    1
    2
    3
    4
    5
    6
    $ unzip -l GeoIP2-City-mmdb.zip
    Archive: GeoIP2-City-mmdb.zip
    Length Date Time Name
    --------- ---------- ----- ----
    0 03-12-2021 11:11 lib/
    120825986 03-10-2021 04:24 lib/GeoIP2-City.mmdb
  2. Upload the zip file to a s3 bucket

    1
    aws s3 cp GeoIP2-City-mmdb.zip s3://lambda-layer-ap-east-1/GeoIP2-City-mmdb.zip --profile prod-calviny --region ap-east-1
  3. Use Cloudformation (or AWS Console) to deploy the layer

    1. Prepare Cloudformation template
      template-layer.yaml
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      AWSTemplateFormatVersion: '2010-09-09'
      Transform: AWS::Serverless-2016-10-31
      Description: API SAM template
      Resources:
      GeoIPDBLayer:
      Type: AWS::Serverless::LayerVersion
      Properties:
      LayerName: geo-ip-city-db-layer
      Description: Dependencies for MaxMind GEO IP DB
      ContentUri: s3://lambda-layer-ap-east-1/GeoIP2-City-mmdb.zip
      CompatibleRuntimes:
      - nodejs14.x
      LicenseInfo: MIT
      RetentionPolicy: Retain
    2. Deploy the layer to AWS
      1
      aws cloudformation deploy --template-file template-layer.yaml --stack-name lambda-layer-stack --profile prod-calviny --region ap-east-1
2021-08-17