Skip to content

Commit

Permalink
rm .DS_Store, add README.md to aws-py-serverless-raw and tests for bo…
Browse files Browse the repository at this point in the history
…th aws-py-serverless-raw and aws-ts-serverless-raw
  • Loading branch information
XUANHE ZHOU committed Jun 30, 2020
1 parent e52dae3 commit db01787
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
Binary file removed .DS_Store
Binary file not shown.
Binary file removed aws-py-serverless-raw/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions aws-py-serverless-raw/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.pyc
.DS_Store
venv/
80 changes: 80 additions & 0 deletions aws-py-serverless-raw/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)

# Serverless C# App

This example deploys a complete serverless C# application using raw `aws.apigateway.RestApi`, `aws.lambda_.Function` and
`aws.dynamodb.Table` resources from `pulumi_aws`. Although this doesn't feature any of the higher-level abstractions
from the `pulumi_cloud` package, it demonstrates that you can program the raw resources directly available in AWS
to accomplish all of the same things this higher-level package offers.

The deployed Lambda function is a simple C# application, highlighting the ability to manage existing application code
in a Pulumi application, even if your Pulumi code is written in a different language like JavaScript or Python.

The Lambda function is a C# application using .NET Core 2.1 (a similar approach works for any other language supported by
AWS Lambda).

## Deploying and running the Pulumi App

1. Create a new stack:

```bash
$ pulumi stack init dev
```

1. Restore NPM modules via `npm install` or `yarn install`.

1. Build the C# application.

```bash
dotnet publish app
```

1. Set the AWS region:

```bash
$ pulumi config set aws:region us-east-2
```

1. Optionally, set AWS Lambda provisioned concurrency:

```bash
$ pulumi config set provisionedConcurrency 1
```

1. Run `pulumi up` to preview and deploy changes:

```
$ pulumi up
Previewing update (dev):
...
Updating (dev):
...
Resources:
+ 10 created
Duration: 1m 20s
```

1. Check the deployed GraphQL endpoint:

```
$ curl $(pulumi stack output endpoint)/hello
{"Path":"/hello","Count":0}
```

1. See the logs

```
$ pulumi logs -f
2018-03-21T18:24:52.670-07:00[ mylambda-d719650] START RequestId: d1e95652-2d6f-11e8-93f6-2921c8ae65e7 Version: $LATEST
2018-03-21T18:24:56.171-07:00[ mylambda-d719650] Getting count for '/hello'
2018-03-21T18:25:01.327-07:00[ mylambda-d719650] Got count 0 for '/hello'
2018-03-21T18:25:02.267-07:00[ mylambda-d719650] END RequestId: d1e95652-2d6f-11e8-93f6-2921c8ae65e7
2018-03-21T18:25:02.267-07:00[ mylambda-d719650] REPORT RequestId: d1e95652-2d6f-11e8-93f6-2921c8ae65e7 Duration: 9540.93 ms Billed Duration: 9600 ms Memory Size: 128 MB Max Memory Used: 37 MB
```

## Clean up

1. Run `pulumi destroy` to tear down all resources.

1. To delete the stack itself, run `pulumi stack rm`. Note that this command deletes all deployment history from the Pulumi Console.
Binary file removed aws-ts-serverless-raw/.DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions misc/test/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"os"
"path"
"regexp"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -246,6 +247,20 @@ func TestAccAwsPyS3Folder(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestAccAwsPyServerlessRaw(t *testing.T) {
test := getAWSBase(t).
With(integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "..", "aws-py-serverless-raw"),
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
assertHTTPResult(t, stack.Outputs["endpoint"].(string)+"/hello", nil, func(body string) bool {
return assert.Regexp(t, regexp.MustCompile("{\"Path\":\"hello\",\"Count\":[0-9]+}"), body)
})
},
})

integration.ProgramTest(t, &test)
}

func TestAccAwsPyStepFunctions(t *testing.T) {
test := getAWSBase(t).
With(integration.ProgramTestOptions{
Expand Down Expand Up @@ -476,6 +491,20 @@ func TestAccAwsTsS3LambdaCopyZip(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestAccAwsTsServerlessRaw(t *testing.T) {
test := getAWSBase(t).
With(integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "..", "aws-ts-serverless-raw"),
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
assertHTTPResult(t, stack.Outputs["endpoint"].(string)+"/hello", nil, func(body string) bool {
return assert.Regexp(t, regexp.MustCompile("{\"Path\":\"hello\",\"Count\":[0-9]+}"), body)
})
},
})

integration.ProgramTest(t, &test)
}

func TestAccAwsTsSlackbot(t *testing.T) {
test := getAWSBase(t).
With(integration.ProgramTestOptions{
Expand Down

0 comments on commit db01787

Please sign in to comment.