Skip to content

Commit a4c8785

Browse files
authored
update blueprint (#48)
1 parent 3df2387 commit a4c8785

File tree

19 files changed

+241
-60
lines changed

19 files changed

+241
-60
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818

19-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v4.1.1
2020

2121
- id: deploy
2222
uses: fogfish/deploy-cdk-go@latest
2323
with:
24-
go-version: "1.20"
24+
go-version: "1.21"
2525
stack: ${{ matrix.stack }}
2626
version: latest
2727
issue-to-create: ./.github/issue-spawn-latest.md

.github/workflows/carry.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515

16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v4.1.1
1717

1818
- id: deploy
1919
uses: fogfish/deploy-cdk-go@latest
2020
with:
21-
go-version: "1.20"
21+
go-version: "1.21"
2222
stack: ${{ matrix.stack }}
2323
version: ${{ github.event.release.name }}
2424
issue-to-create: ./.github/issue-spawn-release.md

.github/workflows/check-clean.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919

20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4.1.1
2121

2222
- uses: fogfish/deploy-cdk-go@latest
2323
with:
24-
go-version: "1.20"
24+
go-version: "1.21"
2525
command: destroy
2626
stack: ${{ matrix.stack }}
2727
version: pr${{ github.event.number }}

.github/workflows/check-code.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616

17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4.1.1
1818

19-
- uses: actions/setup-go@v3
19+
- uses: actions/setup-go@v5
2020
with:
21-
go-version: "1.20"
21+
go-version: "1.21"
2222
cache: true
2323

24-
- uses: dominikh/staticcheck-action@v1.2.0
24+
- uses: dominikh/staticcheck-action@v1.3.0
2525
with:
2626
install-go: false

.github/workflows/check-spawn.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ jobs:
1818

1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v4.1.1
2222

2323
- id: deploy
2424
uses: fogfish/deploy-cdk-go@latest
2525
with:
26-
go-version: "1.20"
26+
go-version: "1.21"
2727
stack: ${{ matrix.stack }}
2828
version: pr${{ github.event.number }}
2929
issue-to-comment: ${{ github.event.number }}

.github/workflows/check-test.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ jobs:
1919
runs-on: ubuntu-latest
2020
steps:
2121

22-
- uses: actions/checkout@v2
22+
- uses: actions/checkout@v4.1.1
2323

24-
- uses: actions/setup-go@v3
24+
- uses: actions/setup-go@v5
2525
with:
26-
go-version: "1.20"
26+
go-version: "1.21"
2727
cache: true
2828

2929
- name: go build
@@ -34,10 +34,8 @@ jobs:
3434
run: |
3535
go test -v -coverprofile=profile.cov $(go list ./... | grep -v /examples/)
3636
env:
37-
## GOPATH required to build serverless app inside unittest
38-
GOPATH: /home/runner/go
39-
GOCACHE: /home/runner/.cache/go-build
40-
GOMODCACHE: /home/runner/go/pkg/mod
37+
## GOPATH required to build serverless app inside unittest
38+
GOPATH: /home/runner/work/${{ github.event.repository.name }}/go
4139

4240
- uses: shogo82148/actions-goveralls@v1
4341
continue-on-error: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ node_modules/
1818
.vscode/
1919

2020
assay-it/
21+
22+
cdk.context.json

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ github.com/.../the-beautiful-app
122122
| |
123123
| ├─ api // public objects used by API
124124
| | └─ pet.go
125+
| ├─ curl // client library
126+
| | └─ petshop.go
125127
| └─ suites // testing suites for api endpoint(s)
126128
|
127129
├─ cmd // executables of the project
@@ -176,10 +178,24 @@ cdk deploy
176178

177179
In few seconds, the application becomes available at
178180

179-
```
181+
```bash
180182
curl https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/api
181183
```
182184

185+
The api is protected by AWS IAM, request has to be signed.
186+
Either use example client `cmd/petshop-cli` or curl directly
187+
188+
```bash
189+
curl $BLUEPRINT/petshop/pets \
190+
-XGET \
191+
-H "Accept: application/json" \
192+
--aws-sigv4 "aws:amz:eu-west-1:execute-api" \
193+
--user "$AWS_ACCESS_KEY_ID":"$AWS_SECRET_ACCESS_KEY"
194+
```
195+
196+
See [all available endpoints](./http/petshop.go).
197+
198+
183199
**test in production**
184200

185201
```bash

cloud/blueprint.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"os"
66

77
"github.com/aws/aws-cdk-go/awscdk/v2"
8-
"github.com/aws/aws-cdk-go/awscdk/v2/awsapigateway"
8+
"github.com/aws/aws-cdk-go/awscdk/v2/awsapigatewayv2"
99
"github.com/aws/constructs-go/constructs/v10"
1010
"github.com/aws/jsii-runtime-go"
1111
"github.com/fogfish/scud"
@@ -35,8 +35,11 @@ func main() {
3535
//
3636
// Stack
3737
//
38-
stackID := fmt.Sprintf("blueprint-golang-%s", vsn(app))
39-
stack := awscdk.NewStack(app, jsii.String(stackID), config)
38+
vsn := vsn(app)
39+
stack := awscdk.NewStack(app,
40+
jsii.String(fmt.Sprintf("blueprint-golang-%s", vsn)),
41+
config,
42+
)
4043

4144
NewBlueprint(stack)
4245

@@ -46,16 +49,17 @@ func main() {
4649
// NewBlueprint create example REST api
4750
func NewBlueprint(scope constructs.Construct) {
4851
gateway := scud.NewGateway(scope, jsii.String("Gateway"),
49-
&awsapigateway.RestApiProps{
50-
RestApiName: jsii.String("petshop"),
52+
&scud.GatewayProps{
53+
HttpApiProps: &awsapigatewayv2.HttpApiProps{},
5154
},
5255
)
56+
gateway.WithAuthorizerIAM()
5357

54-
myfun := scud.NewFunctionGo(scope, jsii.String("MyFun"),
58+
handler := scud.NewFunctionGo(scope, jsii.String("Handler"),
5559
&scud.FunctionGoProps{
5660
SourceCodePackage: "github.com/fogfish/blueprint-serverless-golang",
5761
SourceCodeLambda: "cmd/lambda/petshop",
5862
},
5963
)
60-
gateway.AddResource("petshop", myfun)
64+
gateway.AddResource("/petshop", handler)
6165
}

cloud/blueprint_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ func TestBlueprint(t *testing.T) {
1515
NewBlueprint(stack)
1616

1717
require := map[*string]*float64{
18-
jsii.String("AWS::ApiGateway::RestApi"): jsii.Number(1),
19-
jsii.String("AWS::ApiGateway::Deployment"): jsii.Number(1),
20-
jsii.String("AWS::ApiGateway::Stage"): jsii.Number(1),
21-
jsii.String("AWS::ApiGateway::Method"): jsii.Number(5),
22-
jsii.String("AWS::IAM::Role"): jsii.Number(3),
23-
jsii.String("AWS::Lambda::Function"): jsii.Number(2),
24-
jsii.String("Custom::LogRetention"): jsii.Number(1),
18+
jsii.String("AWS::ApiGatewayV2::Api"): jsii.Number(1),
19+
jsii.String("AWS::ApiGatewayV2::Stage"): jsii.Number(2),
20+
jsii.String("AWS::ApiGatewayV2::Route"): jsii.Number(1),
21+
jsii.String("AWS::IAM::Role"): jsii.Number(2),
22+
jsii.String("AWS::Lambda::Function"): jsii.Number(2),
23+
jsii.String("Custom::LogRetention"): jsii.Number(1),
2524
}
2625

2726
template := assertions.Template_FromStack(stack, nil)

0 commit comments

Comments
 (0)