jacob-meacham / serverless-plugin-bind-deployment-id

:link: Serverless plugin to bind the randomly generated deployment id to custom resources
MIT License
33 stars 7 forks source link

Every Resources object must contain a Type member #4

Closed chrisjgray closed 7 years ago

chrisjgray commented 7 years ago

When I attempt to implement your solution I get the following error:

Serverless Error ---------------------------------------

 Template format error: [/Resources/__deployment__] Every
 Resources object must contain a Type member.

my serverless.yml Sanitized

provider:
  name: aws
  runtime: python2.7
  memorySize: 128
  timeout: 15
  versionFunctions: false
  role: arn:aws:iam::sanitized
  vpc:
    securityGroupIds:
      - sg-sanitized
    subnetIds:
      - subnet-sanitized
      - subnet-sanitized
  region: us-west-2
  apiKeys:
    - workaroundkey
package:
  exclude:
    - node_modules/**
functions:
  auth:
    handler: sanitized
    name: sanitized-${opt:stage}
    description: Pre-Authentication Lambda
    events:
      - http: POST auth
  oauth:
    handler: sanitized.sanitized
    name: sanitized-${opt:stage}
    description: App oauth Lambda
    events:
      - http: GET oauth        
      - http: POST oauth
resources:
  Resources:
    pathmapping:
      DependsOn: ApiGatewayApiKey1
      Type: AWS::ApiGateway::BasePathMapping
      Properties:
        BasePath: ${opt:stage}
        DomainName: sanitized
        RestApiId: __deployment__
        Stage: ${opt:stage}
    __deployment__:
      Properties:
        DataTraceEnabled: true
        MetricsEnabled: true
plugins:
  - serverless-plugin-bind-deployment-id
jacob-meacham commented 7 years ago

Hi @FritzSG - sorry for the trouble you've had! I'll be sure to take a look at this tonight and let you know what's going on. Thanks!

jacob-meacham commented 7 years ago

What version of serverless are you running?

jacob-meacham commented 7 years ago

As I just discussed in the README, right now you have to, unfortunately, make a different stage with a stable id. These stages are pretty simple to ignore, since they never show up anywhere - we're currently deploying ~20 microservices across staging and prod right now, and haven't had a problem with them. The way I'd structure your resources from above:

resources:
  Resources:
    pathmapping:
      Type: AWS::ApiGateway::BasePathMapping
      DependsOn: ApiGatewayStage
      Properties:
        BasePath: ${opt:stage}
        DomainName: sanitized
        RestApiId:
          Ref: ApiGatewayRestApi
        Stage: ${opt:stage}
    ApiGatewayStage:
      Type: AWS::ApiGateway::Stage
      Properties:
        DeploymentId:
          Ref: __deployment__
        RestApiId:
          Ref: ApiGatewayRestApi
        StageName : ${opt:stage}
        MethodSettings:
          - DataTraceEnabled: true
            MetricsEnabled: true

Notice that you shouldn't have to use an API key workaround anymore either.

jacob-meacham commented 7 years ago

I'm going to close this, but please reopen if the above doesn't fix things for you. Thanks!

chrisjgray commented 7 years ago

Still having issues. All I did was replace the resources section with what you pasted and replaced the sanitized with the actual domain name, and pasted that into my config.

Serverless: Packaging service... Serverless: Uploading CloudFormation file to S3... Serverless: Uploading service .zip file to S3 (5.62 KB)... Serverless: Updating Stack... Serverless: Checking Stack update progress... CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - chatops-auth-Dev CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - AuthLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - OauthLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - AuthLogGroup CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - AuthLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - OauthLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - OauthLogGroup CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::RestApi - ApiGatewayRestApi CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - AuthLambdaFunction CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::BasePathMapping - pathmapping CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceAuth CloudFormation - CREATE_FAILED - AWS::ApiGateway::BasePathMapping - pathmapping CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - OauthLambdaFunction CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceAuth CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - AuthLambdaFunction CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Resource - ApiGatewayResourceAuth CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceOauth CloudFormation - CREATE_FAILED - AWS::Lambda::Function - AuthLambdaFunction CloudFormation - CREATE_FAILED - AWS::ApiGateway::Resource - ApiGatewayResourceOauth CloudFormation - CREATE_FAILED - AWS::Lambda::Function - OauthLambdaFunction CloudFormation - UPDATE_ROLLBACK_IN_PROGRESS - AWS::CloudFormation::Stack - chatops-auth-Dev CloudFormation - UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - chatops-auth-Dev CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::BasePathMapping - pathmapping CloudFormation - DELETE_IN_PROGRESS - AWS::Lambda::Function - OauthLambdaFunction CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceAuth CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::Resource - ApiGatewayResourceOauth CloudFormation - DELETE_IN_PROGRESS - AWS::Lambda::Function - AuthLambdaFunction CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::Resource - ApiGatewayResourceAuth CloudFormation - DELETE_COMPLETE - AWS::Lambda::Function - OauthLambdaFunction CloudFormation - DELETE_COMPLETE - AWS::Lambda::Function - AuthLambdaFunction CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - OauthLogGroup CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - AuthLogGroup CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - OauthLogGroup CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - AuthLogGroup CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::RestApi - ApiGatewayRestApi CloudFormation - UPDATE_ROLLBACK_COMPLETE - AWS::CloudFormation::Stack - chatops-auth-Dev Serverless: Deployment failed!

Serverless Error ---------------------------------------

 An error occurred while provisioning your stack: pathmapping
 - Invalid stage identifier specified.

Get Support -------------------------------------------- Docs: docs.serverless.com Bugs: github.com/serverless/serverless/issues Forums: forum.serverless.com Chat: gitter.im/serverless/serverless

Your Environment Information ----------------------------- OS: linux Node Version: 4.2.2 Serverless Version: 1.10.1

chrisjgray commented 7 years ago

I went ahead and added the DependsOn: ApiGatewayStage to the path mapping and got further but ran into a separate issue.

Serverless: Packaging service... Serverless: Uploading CloudFormation file to S3... Serverless: Uploading service .zip file to S3 (5.62 KB)... Serverless: Updating Stack... Serverless: Checking Stack update progress... CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - chatops-auth-Dev CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - OauthLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - AuthLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - OauthLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - OauthLogGroup CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::RestApi - ApiGatewayRestApi CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - AuthLogGroup CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - AuthLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceAuth CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - AuthLambdaFunction CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceOauth CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - OauthLambdaFunction CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceOauth CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Resource - ApiGatewayResourceOauth CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceAuth CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - OauthLambdaFunction CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - AuthLambdaFunction CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Resource - ApiGatewayResourceAuth CloudFormation - CREATE_COMPLETE - AWS::Lambda::Function - AuthLambdaFunction CloudFormation - CREATE_COMPLETE - AWS::Lambda::Function - OauthLambdaFunction CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - OauthLambdaPermissionApiGateway CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodOauthPost CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodOauthGet CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodOauthPost CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - AuthLambdaPermissionApiGateway CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodOauthGet CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Method - ApiGatewayMethodOauthPost CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - AuthLambdaPermissionApiGateway CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Method - ApiGatewayMethodOauthGet CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodAuthPost CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - OauthLambdaPermissionApiGateway CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodAuthPost CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Method - ApiGatewayMethodAuthPost CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Deployment - ApiGatewayDeployment1490881036428 CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Deployment - ApiGatewayDeployment1490881036428 CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Deployment - ApiGatewayDeployment1490881036428 CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Stage - ApiGatewayStage CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Stage - ApiGatewayStage CloudFormation - CREATE_COMPLETE - AWS::Lambda::Permission - OauthLambdaPermissionApiGateway CloudFormation - CREATE_FAILED - AWS::ApiGateway::Stage - ApiGatewayStage CloudFormation - CREATE_COMPLETE - AWS::Lambda::Permission - AuthLambdaPermissionApiGateway CloudFormation - UPDATE_ROLLBACK_IN_PROGRESS - AWS::CloudFormation::Stack - chatops-auth-Dev CloudFormation - UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - chatops-auth-Dev CloudFormation - DELETE_IN_PROGRESS - AWS::Lambda::Permission - OauthLambdaPermissionApiGateway CloudFormation - DELETE_IN_PROGRESS - AWS::Lambda::Permission - AuthLambdaPermissionApiGateway CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::Stage - ApiGatewayStage CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::Stage - ApiGatewayStage CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::Deployment - ApiGatewayDeployment1490881036428 CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::Deployment - ApiGatewayDeployment1490881036428 CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodAuthPost CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodOauthGet CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodOauthPost CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::Method - ApiGatewayMethodOauthGet CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::Method - ApiGatewayMethodOauthPost CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::Method - ApiGatewayMethodAuthPost CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceOauth CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::Resource - ApiGatewayResourceOauth CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceAuth CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::Resource - ApiGatewayResourceAuth CloudFormation - DELETE_COMPLETE - AWS::Lambda::Permission - AuthLambdaPermissionApiGateway CloudFormation - DELETE_COMPLETE - AWS::Lambda::Permission - OauthLambdaPermissionApiGateway CloudFormation - DELETE_IN_PROGRESS - AWS::Lambda::Function - OauthLambdaFunction CloudFormation - DELETE_IN_PROGRESS - AWS::Lambda::Function - AuthLambdaFunction CloudFormation - DELETE_COMPLETE - AWS::Lambda::Function - OauthLambdaFunction CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi CloudFormation - DELETE_COMPLETE - AWS::Lambda::Function - AuthLambdaFunction CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::RestApi - ApiGatewayRestApi CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - OauthLogGroup CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - AuthLogGroup CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - OauthLogGroup CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - AuthLogGroup CloudFormation - UPDATE_ROLLBACK_COMPLETE - AWS::CloudFormation::Stack - chatops-auth-Dev Serverless: Deployment failed!

Serverless Error ---------------------------------------

 An error occurred while provisioning your stack: ApiGatewayStage
 - Invalid method setting path: null/null/metrics/enabled.
 Must be one of: [/deploymentId, /description, /cacheClusterEnabled/cacheClusterSize/clientCertificateId/{resourcePath}/{httpMethod}/metrics/enabled,
 /{resourcePath}/{httpMethod}/logging/dataTrace, /{resourcePath}/{httpMethod}/logging/loglevel,
 /{resourcePath}/{httpMethod}/throttling/burstLimit/{resourcePath}/{httpMethod}/throttling/rateLimit/{resourcePath}/{httpMethod}/caching/ttlInSeconds,
 /{resourcePath}/{httpMethod}/caching/enabled, /{resourcePath}/{httpMethod}/caching/dataEncrypted,
 /{resourcePath}/{httpMethod}/caching/requireAuthorizationForCacheControl,
 /{resourcePath}/{httpMethod}/caching/unauthorizedCacheControlHeaderStrategy,
 /*/*/metrics/enabled, /*/*/logging/dataTrace, /*/*/logging/loglevel,
 /*/*/throttling/burstLimit /*/*/throttling/rateLimit
 /*/*/caching/ttlInSeconds, /*/*/caching/enabled, /*/*/caching/dataEncrypted,
 /*/*/caching/requireAuthorizationForCacheControl, /*/*/caching/unauthorizedCacheControlHeaderStrategy,
 /variables/{variable_na.
chrisjgray commented 7 years ago

Hrmm... weirdness ensues. So, I made some slight changes to my code and it deployed but now I have 2 copies of the same API listed, and both have the same stage, but one has the __unused_stage__ as well.

resources:
  Resources:
    pathmapping:
      Type: AWS::ApiGateway::BasePathMapping
      DependsOn: ApiGatewayStage
      Properties:
        BasePath: ${opt:stage}
        DomainName: sanitized
        RestApiId:
          Ref: ApiGatewayRestApi
        Stage: ${opt:stage}
    ApiGatewayStage:
      Type: AWS::ApiGateway::Stage
      Properties:
        DeploymentId:
          Ref: __deployment__
        RestApiId:
          Ref: ApiGatewayRestApi
        StageName : ${opt:stage}
        MethodSettings:
          - DataTraceEnabled: true
            HttpMethod: "*"
            LoggingLevel: INFO
            ResourcePath: "/*"
            MetricsEnabled: true

image

chrisjgray commented 7 years ago

BAHAHAHAHA! After multiple iterations I have it working. Thanks. Working combo for me without any duplicates:

resources:
  Resources:
    pathmapping:
      Type: AWS::ApiGateway::BasePathMapping
      DependsOn: ApiGatewayStage
      Properties:
        BasePath: ${opt:stage}
        DomainName: sanitized
        RestApiId:
          Ref: ApiGatewayRestApi
        Stage: ${opt:stage}
    ApiGatewayStage:
      Type: AWS::ApiGateway::Stage
      Properties:
        DeploymentId:
          Ref: __deployment__
        RestApiId:
          Ref: ApiGatewayRestApi
        StageName : ${opt:stage}
plugins:
  -  serverless-plugin-bind-deployment-id