├── .gitignore ├── README.md ├── main.go └── serverless.yml /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | 3 | # Serverless directories 4 | .serverless -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UPDATE 2 | 3 | Starting from [version 1.26](https://github.com/serverless/serverless/releases/tag/v1.26.0) Serverless Framework includes two Golang templates: 4 | 5 | * `aws-go` - basic template with two functions 6 | * `aws-go-dep` - **recommended** template using [`dep`](https://github.com/golang/dep) package manager 7 | 8 | You can use them with `create` command: 9 | 10 | ``` 11 | serverless create -t aws-go-dep 12 | ``` 13 | 14 | Original README below. 15 | 16 | --- 17 | 18 | # Serverless Template for Golang 19 | 20 | This repository contains template for creating serverless services written in Golang. 21 | 22 | ## Quick Start 23 | 24 | 1. Create a new service based on this template 25 | 26 | ``` 27 | serverless create -u https://github.com/serverless/serverless-golang/ -p myservice 28 | ``` 29 | 30 | 2. Compile function 31 | 32 | ``` 33 | cd myservice 34 | GOOS=linux go build -o bin/main 35 | ``` 36 | 37 | 3. Deploy! 38 | 39 | ``` 40 | serverless deploy 41 | ``` 42 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/aws/aws-lambda-go/lambda" 5 | ) 6 | 7 | type Response struct { 8 | Message string `json:"message"` 9 | } 10 | 11 | func Handler() (Response, error) { 12 | return Response{ 13 | Message: "Go Serverless v1.0! Your function executed successfully!", 14 | }, nil 15 | } 16 | 17 | func main() { 18 | lambda.Start(Handler) 19 | } 20 | -------------------------------------------------------------------------------- /serverless.yml: -------------------------------------------------------------------------------- 1 | # Welcome to Serverless! 2 | # 3 | # This file is the main config file for your service. 4 | # It's very minimal at this point and uses default values. 5 | # You can always add more config options for more control. 6 | # We've included some commented out config examples here. 7 | # Just uncomment any of them to get that config option. 8 | # 9 | # For full config options, check the docs: 10 | # docs.serverless.com 11 | # 12 | # Happy Coding! 13 | 14 | service: aws-golang # NOTE: update this with your service name 15 | 16 | # You can pin your service to only deploy with a specific Serverless version 17 | # Check out our docs for more details 18 | # frameworkVersion: "=X.X.X" 19 | 20 | provider: 21 | name: aws 22 | runtime: go1.x 23 | 24 | # you can overwrite defaults here 25 | # stage: dev 26 | # region: us-east-1 27 | 28 | # you can add statements to the Lambda function's IAM Role here 29 | # iamRoleStatements: 30 | # - Effect: "Allow" 31 | # Action: 32 | # - "s3:ListBucket" 33 | # Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] } 34 | # - Effect: "Allow" 35 | # Action: 36 | # - "s3:PutObject" 37 | # Resource: 38 | # Fn::Join: 39 | # - "" 40 | # - - "arn:aws:s3:::" 41 | # - "Ref" : "ServerlessDeploymentBucket" 42 | # - "/*" 43 | 44 | # you can define service wide environment variables here 45 | # environment: 46 | # variable1: value1 47 | 48 | package: 49 | exclude: 50 | - ./** 51 | include: 52 | - ./bin/** 53 | 54 | functions: 55 | hello: 56 | handler: bin/main 57 | 58 | # The following are a few example events you can configure 59 | # NOTE: Please make sure to change your handler code to work with those events 60 | # Check the event documentation for details 61 | # events: 62 | # - http: 63 | # path: users/create 64 | # method: get 65 | # - s3: ${env:BUCKET} 66 | # - schedule: rate(10 minutes) 67 | # - sns: greeter-topic 68 | # - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000 69 | # - alexaSkill 70 | # - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx 71 | # - iot: 72 | # sql: "SELECT * FROM 'some_topic'" 73 | # - cloudwatchEvent: 74 | # event: 75 | # source: 76 | # - "aws.ec2" 77 | # detail-type: 78 | # - "EC2 Instance State-change Notification" 79 | # detail: 80 | # state: 81 | # - pending 82 | # - cloudwatchLog: '/aws/lambda/hello' 83 | # - cognitoUserPool: 84 | # pool: MyUserPool 85 | # trigger: PreSignUp 86 | 87 | # Define function environment variables here 88 | # environment: 89 | # variable2: value2 90 | 91 | # you can add CloudFormation resource templates here 92 | #resources: 93 | # Resources: 94 | # NewResource: 95 | # Type: AWS::S3::Bucket 96 | # Properties: 97 | # BucketName: my-new-bucket 98 | # Outputs: 99 | # NewOutput: 100 | # Description: "Description for the output" 101 | # Value: "Some output value" 102 | --------------------------------------------------------------------------------