Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sapessi committed Feb 5, 2018
2 parents d92644b + 7ed321a commit aa5bddc
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -79,6 +79,14 @@ sam --version

If you get a permission error when using npm (such as `EACCES: permission denied`), please see the instructions on this page of the NPM documentation: [https://docs.npmjs.com/getting-started/fixing-npm-permissions](https://docs.npmjs.com/getting-started/fixing-npm-permissions).

#### Upgrading via npm

To update **`sam`** once installed via npm:

```bash
npm update -g aws-sam-local
```

### Binary release

We also release the CLI as binaries that you can download and instantly use. You can find them under [Releases] in this repo. In case you cannot find the version or architecture you're looking for you can refer to [Build From Source](#build-from-source) section for build details.
Expand Down
26 changes: 22 additions & 4 deletions runtime.go
Expand Up @@ -81,13 +81,15 @@ var runtimeName = struct {
python27 string
python36 string
java8 string
go1x string
}{
nodejs: "nodejs",
nodejs43: "nodejs4.3",
nodejs610: "nodejs6.10",
python27: "python2.7",
python36: "python3.6",
java8: "java8",
go1x: "go1.x",
}

var runtimeImageFor = map[string]string{
Expand All @@ -97,6 +99,7 @@ var runtimeImageFor = map[string]string{
runtimeName.python27: "lambci/lambda:python2.7",
runtimeName.python36: "lambci/lambda:python3.6",
runtimeName.java8: "lambci/lambda:java8",
runtimeName.go1x: "lambci/lambda:go1.x",
}

// NewRuntimeOpt contains parameters that are passed to the NewRuntime method
Expand Down Expand Up @@ -289,6 +292,22 @@ func (r *Runtime) Invoke(event string, profile string) (io.Reader, io.Reader, er
}
}

// If the timeout hasn't been set for the function in the SAM template
// then default to 3 seconds (as per SAM specification).
// This needs to be done before environment variables are generated for
// the Lambda runtime so that the correct AWS_LAMBDA_FUNCTION_TIMEOUT is used
if r.Function.Timeout <= 0 {
r.Function.Timeout = 3
}

// If the memory size hasn't been set for the function in the SAM template
// then default to 128MB (as per SAM specification).
// This needs to be done before environment variables are generated for
// the Lambda runtime so that the correct AWS_LAMBDA_FUNCTION_MEMORY_SIZE is used
if r.Function.MemorySize <= 0 {
r.Function.MemorySize = 128
}

// Define the container options
config := &container.Config{
WorkingDir: "/var/task",
Expand Down Expand Up @@ -360,11 +379,10 @@ func (r *Runtime) Invoke(event string, profile string) (io.Reader, io.Reader, er
}

func (r *Runtime) setupTimeoutTimer(stdout, stderr io.ReadCloser) {

// Start a timer, we'll use this to abort the function if it runs beyond the specified timeout
timeout := time.Duration(3) * time.Second
if r.Function.Timeout > 0 {
timeout = time.Duration(r.Function.Timeout) * time.Second
}
timeout := time.Duration(r.Function.Timeout) * time.Second

r.TimeoutTimer = time.NewTimer(timeout)
go func() {
<-r.TimeoutTimer.C
Expand Down
33 changes: 33 additions & 0 deletions samples/hello-world/golang/README.md
@@ -0,0 +1,33 @@
# AWS SAM Hello World Example #

A simple AWS SAM template that specifies a single Lambda function.

## Usage ##

To create and deploy the SAM Hello World example, first ensure that you've met the requirements described in the [root README](../../README.md). Then follow the steps below.

### Build your package ###

GOOS=linux go build -o main

### Test your application locally ###

Use [SAM Local](https://github.com/awslabs/aws-sam-local) to run your Lambda function locally:

sam local invoke "HelloWorld" -e event.json

### Package artifacts ###

Run the following command, replacing `BUCKET-NAME` with the name of your bucket:

sam package --template-file template.yaml --s3-bucket BUCKET-NAME --output-template-file packaged-template.yaml

This creates a new template file, packaged-template.yaml, that you will use to deploy your serverless application.

### Deploy to AWS CloudFormation ###

Run the following command, replacing `MY-NEW-STACK` with a name for your CloudFormation stack.

sam deploy --template-file packaged-template.yaml --stack-name MY-NEW-STACK --capabilities CAPABILITY_IAM

This uploads your template to an S3 bucket and deploys the specified resources using AWS CloudFormation.
5 changes: 5 additions & 0 deletions samples/hello-world/golang/event.json
@@ -0,0 +1,5 @@
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
22 changes: 22 additions & 0 deletions samples/hello-world/golang/main.go
@@ -0,0 +1,22 @@
package main

import (
"fmt"
"log"
"context"
"github.com/aws/aws-lambda-go/lambda"
)

type Event map[string]interface{}

func HandleRequest(ctx context.Context, event Event) (string, error) {
log.Print("value1 = ", event["key1"] )
log.Print("value2 = ", event["key2"] )
log.Print("value3 = ", event["key3"] )

return fmt.Sprintf("Hello World"), nil
}

func main() {
lambda.Start(HandleRequest)
}
11 changes: 11 additions & 0 deletions samples/hello-world/golang/template.yaml
@@ -0,0 +1,11 @@
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Description: A simple Hello World Serverless project
Resources:
HelloWorld:
Type: AWS::Serverless::Function
Properties:
Runtime: go1.x
Handler: main
CodeUri: .

0 comments on commit aa5bddc

Please sign in to comment.