AWS – Serverless Yaml Template
     发布在:JavaScript      浏览:5      评论:0 条评论
service: demo-lambda-function

# Global Setting
provider:
  name: aws
  runtime: nodejs8.10
  stage: dev
  memorySize: 3008
  timeout: 90
  logRetentionInDays: 14
  region: ap-northeast-1
  vpc: 'vpc-06587861'
  securityGroupIds:
    - 'sg-014343b15c7e122c4'
  subnetIds:
    - 'subnet-4774816c'
  environment:
    REGION: 'ap-northeast-1'
    S3_API_VERSION: '2006-03-01'
    SQS_API_VERSION: '2012-11-05'
    CRAWLER_INTERVAL: 250
    CRAWLER_MAX_CONCURRENCY: 100
    CRAWLER_MAX_DEPTH: 2

# IAM Role Setting
iamRoleStatements:
  - Effect: "Allow"
    Action:
      - "s3:Get*"
      - "s3:ListBucket"
      - "s3:*"
    Resource:
      - "arn:aws:s3:::demo"
  - Effect: "Allow"
    Action:
      - "s3:Get*"
      - "s3:ListBucket"
      - "s3:*"
    Resource:
      - "arn:aws:s3:::demo/*"

# Resources Setting
resources:
  Resources:
    LambdaCustomRole:
      Type: AWS::IAM::Role
      Properties:
        RoleName: LambdaCustomRole
        Path: /service-role/
        AssumeRolePolocyDocument:
          Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Principal:
                Service:
                  - lambda.amazonaws.com
                  - apigateway.amazonaws.com
                Action:
                  - sts:AssumeRole
        ManagedPolicyArns:
          - arn:aws:iam::aws:policy/AmazonEC2FullAccess
          - arn:aws:iam::aws:policy/AWSLambdaFullAccess
          - arn:aws:iam::aws:policy/AmazonS3FullAccess
          - arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole
          - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
          - arn:aws:iam::aws:policy/AmazonDRSVPCManagement
          - arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
    CrewlerQueue:
      Type: AWS::SQS::Queue
      Properties:
        QueueName: CrawlerQueue
        DelaySeconds: 5
        VisibilityTimeout: 95
        MessageRetentionPeriod: 1209600

package:
  artifact: ./package.zip
  exclude:
    - node_modules/**

plugins:
  - serverless-hooks-plugin
  - serverless-offline

custom:
  role: arn:aws:iam::000000000000:role/service-role/LambdaCustomRole
  layer: arn:aws:lambda:ap-northeast-1:000000000000:layer:global-lambda-layer:6
  vpc: {
    securityGroupIds: ["sg-014343b15c7e122c4"],
    subnetIds: ["subnet-4774816c"],
  }

function:
  api-compare-function:
    handler: api_handler.compare
    memorySize: 512
    timeout: 30
    role: ${self:custom.role}
    vpc: ${self:custom.vpc}
    layers:
      - ${self:custom.layer}
    events:
      - http:
          path: compare/retrieve-all
          method: get
          cors: true
    Responses