Giter VIP home page Giter VIP logo

forum's Issues

serverless.yml でAPI Gateway VPC integrationを設定したい

やりたい事

serverless.yml のResourcesでAPI Gateway VPC integrationを設定したいです。

前提条件

通信に必要なNLBは既に作成済で疎通確認も出来ています。

やった事

serverless.yml に以下の記述を追加しデプロイを実行。

resources:
  Resources:
    ApiGatewayRestApi:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: ${env:DEPLOY_STAGE}-serverless-vpc-integration
        Description: 'The main entry point of test APIs'
    MainApiBasePath:
      Type: AWS::ApiGateway::Resource
      Properties:
        ParentId:
          Fn::GetAtt:
            - ApiGatewayRestApi
            - RootResourceId
        PathPart: 'main-api'
        RestApiId:
          Ref: ApiGatewayRestApi
    MainApiProxyPath:
      Type: AWS::ApiGateway::Resource
      Properties:
        ParentId:
          Ref: MainApiBasePath
        PathPart: '{proxy+}'
        RestApiId:
          Ref: ApiGatewayRestApi
    MainApiVpcLink:
      Type: AWS::ApiGateway::VpcLink
      Properties:
        Description: 'VPC LINK'
        Name: 'serverless-vpc-integration-1a'
        TargetArns:
         - arn:aws:elasticloadbalancing:ap-northeast-1:{AWSAccountId}:loadbalancer/net/serverless-vpc-integration-1a/{AWSNLBId}
    MainApiProxyAnyMethod:
      Type: AWS::ApiGateway::Method
      Properties:
        AuthorizationType: NONE
        HttpMethod: ANY
        Integration:
          IntegrationHttpMethod: ANY
          Type: VPC_LINK
          Uri: http://serverless-vpc-integration-1a-{AWSNLBId}.elb.ap-northeast-1.amazonaws.com/{proxy}
          PassthroughBehavior: WHEN_NO_MATCH
          RequestParameters:
            'integration.request.path.proxy': 'method.request.path.proxy'
        MethodResponses:
          - StatusCode: 200
        RequestParameters:
            'method.request.path.proxy': true
        ResourceId:
          Ref: MainApiProxyPath
        RestApiId:
          Ref: ApiGatewayRestApi
    MainApiDeployment:
      Type: AWS::ApiGateway::Deployment
      Properties:
        RestApiId:
          Ref: ApiGatewayRestApi
        StageName: ${env:DEPLOY_STAGE}

以下のエラーが発生しました。

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

  An error occurred: MainApiProxyAnyMethod - 1 validation error detected: Value 'VPC_LINK' at 'putIntegrationInput.type' failed to satisfy constraint: Member must satisfy enum value set: [HTTP, MOCK, AWS_PROXY, HTTP_PROXY, AWS].

Amazon API Gateway REST API Reference を見ると、まだ VPC_LINK には対応していないようでした。

※ ちなみに AWS::ApiGateway::Method.Integration.TypeVPC_LINK を設定する行為には失敗しましたが、MainApiVpcLink のResources作成自体には成功しています。

こちら がまだcloseしていない事から、現時点では対応出来ないという認識で良いでしょうか?

現時点で構築手段があれば教えて頂けると幸いです。。

お手数ですがよろしくお願いします!

functionsのファイル読み込みについて

初めまして、sueken5と言います。よろしくお願いします。

functionsについての質問です。

公式のdocmentには以下のような記述に対応しているとあるのですが、このように書くと

# serverless.yml
...

functions:
  - ${file(../foo-functions.yml)}
  - ${file(../bar-functions.yml)}
Missing "handler" property in function "0". Please make sure you point to the correct lambda handler. For example: handler.hello. Please check the docs for more info

というエラーが出てしまいます。どうしたら良いのでしょうか?よろしくお願いします。

Unzipped size must be smaller than 262144000 bytes.について

度々の質問申し訳ありません。sueken5です。

今回は

Unzipped size must be smaller than 262144000 bytes.

の質問に参りました。

このようなエラーが出ているので対象となっている関数のコードサイズを確認してみましたところ、以下のように表示されました。

$ ls -lh

-rwxr-xr-x  XXXXXXXX  staff   8.0M Apr 28 23:34 XXXXXXXX

上記ではコードサイズは「8.0M」でしたのでデプロイ制限にかかってないと思われます。

憶測ではありますが、コードサイズは一関数ごとではなく、デプロイするコードの合計になってしまうのでしょうか?

もしそうであるならば、推奨しているやり方があったりしないでしょうか?

よろしくお願いします。

serverless.ymlのpackage: excludeが効いてない

serverless.ymlにGLOB形式で以下のように書くと、
デプロイパッケージにserverless.ymlが含まれ、node_modules/aws-sdk/以下のファイルは除外できると思うのですが、
Lambdaからデプロイパッケージを取得して確認してみると、serverless.ymlは含まれるのですが、node_modules/aws-sdk/以下のファイルが含まれてました。

package:
  include:
    - serverless.yml
  exclude:
    - node_modules/aws-sdk/**

自分がどこか書き間違えてるのでしょうか、それともバグなのでしょうか?

serverless: v1.17.0

`npm install serverless --save` でインストールするとpostinstall.jsでエラーになる

This is a Bug Report

Description

本来のインストール方法は npm install serverless -g だと思うのですが、これを npm install serverless --save でプロジェクト内にインストールするとpostinstall.jsでエラーになります。

postinstall.jsがautocompletionを設定するためにtabtabを実行する処理だということは理解しています。

その上で、どれが正しいのかがわかりません。

  1. npm install serverless --save は想定していないのでサポート外(バグではない)
  2. バグなのでpostinstall.jsが動くように直すべき
  3. バグだが、 npm install serverless --save のときにはpostinstall.jsは動くべきではない(.zshrcを操作すべきではない)
  4. 実は回避する方法がある

誰か教えてもらえませんでしょうか?

Similar or dependent issues:

Additional Data

  • Serverless Framework Version you're using: 1.15.3
  • Operating System: macOS 10.11.6
  • Stack Trace:
> [email protected] postinstall /Users/k1low/.ghq/github.com/faultline/faultline/node_modules/serverless
> node ./scripts/postinstall.js

module.js:471
    throw err;
    ^

Error: Cannot find module '/Users/k1low/.ghq/github.com/faultline/faultline/node_modules/serverless/node_modules/tabtab/src/cli.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:508:3
module.js:471
    throw err;
    ^

Error: Cannot find module '/Users/k1low/.ghq/github.com/faultline/faultline/node_modules/serverless/node_modules/tabtab/src/cli.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:508:3
  • Provider Error messages:

None

functionsで生成されるS3バケットARNをResourcesから参照したい

解決したい事

functions:
  myFunction:
    handler: dist/app/function/index.myFunction
    warmup: true
    events:
      - s3:
          bucket: myBucketName
          event: s3:ObjectCreated:*

このように関数を定義すると自動的にS3Bucketが作成されます。

しかしここで生成される予定のBucketARNをResourcesで作成したKinesisFirehoseの BucketARN に指定すると以下のエラーが発生します。

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

  An error occurred: AccountApiKinesisFirehose - S3 Bucket myBucketName does not exist. (Service: AmazonKinesisFirehose; Status Code: 400; Error Code: InvalidArgumentException; Request ID: 9862e9ed-1586-4ccf-9812-4b78df73f521).

ResourcesからmyFunctionが裏側で生成したBucket名が取れると良いのですが、上手くいきませんでした。

何か良い方法があれば教えて頂けると助かります🙇

resources:
  Resources:
    FirehoseRole:
      Type: AWS::IAM::Role
      Properties:
        RoleName: FirehoseRole
        AssumeRolePolicyDocument:
          Statement:
            - Effect: Allow
              Principal:
                Service:
                  - firehose.amazonaws.com
              Action:
                - sts:AssumeRole
        Policies:
        - PolicyName: FirehoseToS3Policy
          PolicyDocument:
            Statement:
              - Effect: Allow
                Action:
                  - s3:AbortMultipartUpload
                  - s3:GetBucketLocation
                  - s3:GetObject
                  - s3:ListBucket
                  - s3:ListBucketMultipartUploads
                  - s3:PutObject
                  - logs:CreateLogGroup
                  - logs:CreateLogStream
                  - logs:PutLogEvents
                Resource: '*'
    MyAthenaQueryResultsBucket:
      Type: AWS::S3::Bucket
      DeletionPolicy: Delete
      Properties:
        BucketName: myQueryResults
    MyKinesisFirehoseLogGroup:
      Type: "AWS::Logs::LogGroup"
      Properties:
        LogGroupName: /aws/kinesisfirehose/MyDeliveryStream
    MyKinesisFirehoseLogStream:
      Type: "AWS::Logs::LogStream"
      Properties:
        LogGroupName:
          Ref: MyKinesisFirehoseLogGroup
        LogStreamName: S3Delivery
    MyKinesisFirehose:
      Type: AWS::KinesisFirehose::DeliveryStream
      Properties:
        DeliveryStreamName: MyDeliveryStream
        S3DestinationConfiguration:
          # ↓この部分をmyFunctionで定義されているBucket名にしたい
          BucketARN: arn:aws:s3:::myBucketName
          BufferingHints:
            IntervalInSeconds: '60'
            SizeInMBs: '5'
          CloudWatchLoggingOptions:
            Enabled: true
            LogGroupName:
              Ref: MyKinesisFirehoseLogGroup
            LogStreamName:
              Ref: MyKinesisFirehoseLogStream
          CompressionFormat: 'UNCOMPRESSED'
          RoleARN: { Fn::GetAtt: [ FirehoseRole, Arn ] }

※ ちなみに最終的にやりたい事は Firehoseで出力したファイルをAthenaのパーティション形式に変換するLambda にあるようにS3(myBucketName)にアップロードされたファイルをAthenaのパーティション形式であるHiveフォーマットに変換する事です。

AWS Lambda "monolithic" vs "single-purposed"

はじめまして。 @akifo です。
よろしくお願いします。

serverless も AWS も初心者です。
serverless を触っていて気になったことがありましたので質問させてください。

Function が増えてくると AWS Lambda で管理辛いのでは?と思い、調べてみると、Function は1つにし、handler のほうでルーティングを制御できそうな気がし、これはどちらがベストプラクティスなんだろうという疑問です。

ベストプラクティスを知りたいです

  • 1つの Function に全て書く
  • 複数の Function に分ける

serverless 利用までの流れ

  • APIサーバーを Go言語で書きたい
  • Lambda と API Gateway で配信すると簡単そう
  • serverless 使うと便利そう

このような記事を見つけたのですが...

(読むのに時間がかかりそうなので、こちらでも質問をさせて頂きました)
https://hackernoon.com/aws-lambda-should-you-have-few-monolithic-functions-or-many-single-purposed-functions-8c3872d4338f

書いた後に気付いたのですが serverless に関する質問ではないので、場所違いの内容でしたらそのままクローズいただければと思います。すみません。。

Variable.jsのパラメータの上書き機能において 'cron(0 0 * * ? *)' というような括弧を含む文字列を利用されることが想定されていない

serverless.ymlで

provider:
  name: aws
  runtime: nodejs6.10
  environment:
    LAMBDA_SCHEDULE: ${env:LAMBDA_SCHEDULE, 'cron(0 0 * * ? *)'}
functions:
    cronFunc:
        handler: handler.cronFunc
        events:
           - schedule:
              rate: ${self:provider.environment.LAMBDA_SCHEDULE}
              enabled: true

というように

  • Lambda Functionの schedule に環境変数を渡したいが、デフォルト値として 'cron(0 0 * * ? *)'

だと、うまくパースされないみたいです。


ちなみに回避策としては

provider:
  name: aws
  runtime: nodejs6.10
  environment:
    LAMBDA_SCHEDULE_DEFAULT: 'cron(0 0 * * ? *)'
    LAMBDA_SCHEDULE: ${env:LAMBDA_SCHEDULE, self:provider.environment.LAMBDA_SCHEDULE_DEFAULT}
functions:
    cronFunc:
        handler: handler.cronFunc
        events:
           - schedule:
              rate: ${self:provider.environment.LAMBDA_SCHEDULE}
              enabled: true

という形で複雑なパースを回避すればなんとかなります。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.