Skip to content

Commit

Permalink
simplifying swagger file, implementing different runtimes and handler…
Browse files Browse the repository at this point in the history
…s for different languages
  • Loading branch information
rogerwelin committed Feb 10, 2020
1 parent 0eabde4 commit 2b91d05
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func runCLI(args []string) {
},
cli.GenericFlag{
Name: "l, language",
Usage: "which language to be used (go, java, node, python, ruby)",
Usage: "which language for lambda to be used (go, java, node, python, ruby)",
Value: &EnumValue{
Enum: []string{"go", "java", "node", "python", "ruby"},
Default: "node",
Expand Down
6 changes: 3 additions & 3 deletions tmpl-languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const packageJson = `
const pythonFunction = `
import json
def lambda_handler(event, context):
def handler(event, context):
dict = { "msg" : "hello world" }
Expand Down Expand Up @@ -94,7 +94,7 @@ type helloWorld struct {
Msg string` + "`" + `json:"msg"` + "`" + `
}
func Handler(ctx context.Context) (Response, error) {
func handler(ctx context.Context) (Response, error) {
msg := helloWorld{Msg: "hwllo world"}
resp, err := json.Marshal(msg)
Expand All @@ -114,7 +114,7 @@ func Handler(ctx context.Context) (Response, error) {
}
func main() {
lambda.Start(Handler)
lambda.Start(handler)
}
`

Expand Down
8 changes: 6 additions & 2 deletions tmpl-sam.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ Resources:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/{{ .LambdaFunctionName }}/app/
Handler: recommendations.lambda_handler
Runtime: python3.7
{{ if and (eq .Language "python")}}Handler: app.handler
Runtime: python3.7{{ end }}{{ if and (eq .Language "ruby")}}Handler: app.handler
Runtime: ruby2.5{{ end }}{{ if and (eq .Language "node")}}Handler: index.js
Runtime: nodejs10.x{{ end }}{{ if and (eq .Language "go")}}Handler: helloworld
Runtime: go1.x{{ end }}{{ if and (eq .Language "java")}}Handler: com.api.HelloWorld
Runtime: java8{{ end }}
MemorySize: 512
Timeout: 5
Tracing: Active
Expand Down
8 changes: 1 addition & 7 deletions tmpl-swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ servers:
description: Production environment URL
paths:
/v1/{{ .LambdaFunctionName }}/{userId}:
/v1/{{ .LambdaFunctionName }}:
get:
summary: hello world endpoint
description: outputs hello world
parameters:
- in: path
name: userId
schema:
type: integer
required: true
responses:
200:
description: "OK"
Expand Down

0 comments on commit 2b91d05

Please sign in to comment.