serverless-japan / forum Goto Github PK
View Code? Open in Web Editor NEWServerless Frameworkの日本語フォーラムです
Serverless Frameworkの日本語フォーラムです
YAMLをJSオブジェクトとして読み込んだ段階のserverless.ymlをいじりたいです。
具体的には file(./config.yml)
などの設定で、config.ymlが存在しなくてもエラーにならずにデプロイをすすめたいのです。
なさそうですが。。
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
というように
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
という形で複雑なパースを回避すればなんとかなります。
はじめまして。 @akifo です。
よろしくお願いします。
serverless も AWS も初心者です。
serverless を触っていて気になったことがありましたので質問させてください。
Function が増えてくると AWS Lambda で管理辛いのでは?と思い、調べてみると、Function は1つにし、handler のほうでルーティングを制御できそうな気がし、これはどちらがベストプラクティスなんだろうという疑問です。
(読むのに時間がかかりそうなので、こちらでも質問をさせて頂きました)
https://hackernoon.com/aws-lambda-should-you-have-few-monolithic-functions-or-many-single-purposed-functions-8c3872d4338f
書いた後に気付いたのですが serverless に関する質問ではないので、場所違いの内容でしたらそのままクローズいただければと思います。すみません。。
本来のインストール方法は npm install serverless -g
だと思うのですが、これを npm install serverless --save
でプロジェクト内にインストールするとpostinstall.jsでエラーになります。
postinstall.jsがautocompletionを設定するためにtabtabを実行する処理だということは理解しています。
その上で、どれが正しいのかがわかりません。
npm install serverless --save
は想定していないのでサポート外(バグではない)npm install serverless --save
のときにはpostinstall.jsは動くべきではない(.zshrcを操作すべきではない)誰か教えてもらえませんでしょうか?
Similar or dependent issues:
> [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
None
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
度々の質問申し訳ありません。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
の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.Type
に VPC_LINK
を設定する行為には失敗しましたが、MainApiVpcLink
のResources作成自体には成功しています。
こちら がまだcloseしていない事から、現時点では対応出来ないという認識で良いでしょうか?
現時点で構築手段があれば教えて頂けると幸いです。。
お手数ですがよろしくお願いします!
@horike37
今からISSUEを立てようと思ったんですが、テンプレートがあると便利に感じました。
提案やバグなどによってわけられるとヒアリングの回数が少なく、解決までの時間の短縮が見込めます。
初めまして、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
というエラーが出てしまいます。どうしたら良いのでしょうか?よろしくお願いします。
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フォーマットに変換する事です。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.