serverless / serverless

⚡ Serverless Framework – Effortlessly build apps that auto-scale, incur zero costs when idle, and require minimal maintenance using AWS Lambda and other managed cloud services.
https://serverless.com
MIT License
46.45k stars 5.71k forks source link

Invalid cloudformation configuration due with YAML node anchor #7208

Open jeffjen opened 4 years ago

jeffjen commented 4 years ago

Runtime

Framework Core: 1.61.0
Plugin: 3.2.7
SDK: 2.2.1
Components Core: 1.1.2
Components CLI: 1.4.0

Problem

service: django-hub

package:
  individually: true
  exclude:
    - "**"

plugins:
  - serverless-wsgi

custom:
  timestamp: ${file(./docker/sls/timestamp.js):now}
  version: 0.0.0-${self:provider.stage}-${self:custom.timestamp}
  stage: ${opt:stage, 'at-ut'}
  wsgi:
    packRequirements: false
    app: django_hub.wsgi.application

x-lambda-property: &lambda-property
  role: arn:aws:iam::000000000000:role/LambdaVpc
  package:
    include:
      - handler.py
  layers:
    - arn:aws:lambda:ap-northeast-1:000000000000:layer:django-at-ut-python-requirements:16

provider:
  name: aws
  runtime: python3.6
  stage: ${env:DEPLOY_STAGE, 'at-ut'}

functions:
  wsgi:
    name: ${self:service}-${self:custom.stage}-wsgi
    handler: wsgi_handler.handler
    provisionedConcurrency: 1
    <<: *lambda-property
    timeout: 29
    events:
      - http: ANY /
      - http: "ANY {proxy+}"

  put_event_consumer:
    name: ${self:service}-${self:custom.stage}-put_event_consumer
    handler: handler.put_event_consumer
    reservedConcurrency: 10
    <<: *lambda-property
    timeout: 10
    events:
      - sqs:
          arn:
            Fn::GetAtt:
              - PutEventQueue
              - Arn
          # Reference https://bit.ly/2RLOTey
          batchSize: 10

resources:
  Resources:
    PutEventQueue:
      Type: "AWS::SQS::Queue"
      Properties:
        QueueName: "put-event-${self:custom.stage}.fifo"
        FifoQueue: true
        RedrivePolicy:
          maxReceiveCount: 1

Running serverless package causes an output of cloudformation template with invalid zip content.

{
  "WsgiLambdaFunction": {
    "Type": "AWS::Lambda::Function",
    "Properties": {
      "Code": {
        "S3Bucket": "ops.orcahub-dev.com",
        "S3Key": "serverless/django-admin-hub/at-ut/1578920651517-2020-01-13T13:04:11.517Z/run_trigger.zip"
      }
    }
  },
  "RunUnderscoretriggerLambdaFunction": {
    "Type": "AWS::Lambda::Function",
    "Properties": {
      "Code": {
        "S3Bucket": "ops.orcahub-dev.com",
        "S3Key": "serverless/django-admin-hub/at-ut/1578920651517-2020-01-13T13:04:11.517Z/run_trigger.zip"
      }
    }
  }
}

Where in the correct case, S3Key should be different for each Function. This problem may or may not had caused provisioned concurrency to fail to deploy alias.

medikoo commented 4 years ago

@jeffjen thanks for report. Can you minimize the test case, so it doesn't involve any plugins.

This problem may or may not had caused provisioned concurrency to fail to deploy alias.

sls package doesn't involve any deployment, and doesn't confirm anything on AWS side, so I take it's not related to it.