File tree Expand file tree Collapse file tree 9 files changed +135
-0
lines changed
build-tests-samples/heft-serverless-stack-tutorial Expand file tree Collapse file tree 9 files changed +135
-0
lines changed Original file line number Diff line number Diff line change
1
+ prod
Original file line number Diff line number Diff line change
1
+ # Getting Started with Serverless Stack (SST)
2
+
3
+ This project was bootstrapped with [ Create Serverless Stack] ( https://docs.serverless-stack.com/packages/create-serverless-stack ) .
4
+
5
+ Start by installing the dependencies.
6
+
7
+ ``` bash
8
+ $ npm install
9
+ ```
10
+
11
+ ## Commands
12
+
13
+ ### ` npm run start `
14
+
15
+ Starts the local Lambda development environment.
16
+
17
+ ### ` npm run build `
18
+
19
+ Build your app and synthesize your stacks.
20
+
21
+ Generates a ` .build/ ` directory with the compiled files and a ` .build/cdk.out/ ` directory with the synthesized CloudFormation stacks.
22
+
23
+ ### ` npm run deploy [stack] `
24
+
25
+ Deploy all your stacks to AWS. Or optionally deploy a specific stack.
26
+
27
+ ### ` npm run remove [stack] `
28
+
29
+ Remove all your stacks and all of their resources from AWS. Or optionally remove a specific stack.
30
+
31
+ ### ` npm run test `
32
+
33
+ Runs your tests using Jest. Takes all the [ Jest CLI options] ( https://jestjs.io/docs/en/cli ) .
34
+
35
+ ## Documentation
36
+
37
+ Learn more about the Serverless Stack.
38
+
39
+ - [ Docs] ( https://docs.serverless-stack.com )
40
+ - [ @serverless-stack/cli ] ( https://docs.serverless-stack.com/packages/cli )
41
+ - [ @serverless-stack/resources ] ( https://docs.serverless-stack.com/packages/resources )
42
+
43
+ ## Community
44
+
45
+ [ Follow us on Twitter] ( https://twitter.com/ServerlessStack ) or [ post on our forums] ( https://discourse.serverless-stack.com ) .
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " heft-serverless-stack-tutorial" ,
3
+ "version" : " 0.1.0" ,
4
+ "private" : true ,
5
+ "scripts" : {
6
+ "test" : " sst test" ,
7
+ "start" : " sst start" ,
8
+ "build" : " sst build" ,
9
+ "deploy" : " sst deploy" ,
10
+ "remove" : " sst remove"
11
+ },
12
+ "eslintConfig" : {
13
+ "extends" : [
14
+ " serverless-stack"
15
+ ]
16
+ },
17
+ "devDependencies" : {
18
+ "@tsconfig/node14" : " ^1.0.1" ,
19
+ "@types/aws-lambda" : " ^8.10.70" ,
20
+ "@types/node" : " <15.0.0" ,
21
+ "typescript" : " 4.4.4" ,
22
+ "@serverless-stack/cli" : " 0.69.0" ,
23
+ "@serverless-stack/resources" : " 0.69.0" ,
24
+ "aws-cdk-lib" : " 2.15.0"
25
+ },
26
+ "dependencies" : {}
27
+ }
Original file line number Diff line number Diff line change
1
+ import { APIGatewayProxyHandlerV2 } from 'aws-lambda' ;
2
+
3
+ export const handler : APIGatewayProxyHandlerV2 = async ( event ) => {
4
+ return {
5
+ statusCode : 200 ,
6
+ headers : { 'Content-Type' : 'text/plain' } ,
7
+ body : `Hello, World! Your request was received at ${ event . requestContext . time } .`
8
+ } ;
9
+ } ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " heft-serverless-stack-tutorial" ,
3
+ "region" : " us-east-1" ,
4
+ "main" : " stacks/index.ts"
5
+ }
Original file line number Diff line number Diff line change
1
+ import * as sst from '@serverless-stack/resources' ;
2
+
3
+ export default class MyStack extends sst . Stack {
4
+ constructor ( scope : sst . App , id : string , props ?: sst . StackProps ) {
5
+ super ( scope , id , props ) ;
6
+
7
+ // Create a HTTP API
8
+ const api = new sst . Api ( this , 'Api' , {
9
+ routes : {
10
+ 'GET /' : 'src/lambda.handler'
11
+ }
12
+ } ) ;
13
+
14
+ // Show the endpoint in the output
15
+ this . addOutputs ( {
16
+ ApiEndpoint : api . url
17
+ } ) ;
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ import MyStack from './MyStack' ;
2
+ import * as sst from '@serverless-stack/resources' ;
3
+
4
+ export default function main ( app : sst . App ) : void {
5
+ // Set default runtime for all functions
6
+ app . setDefaultFunctionProps ( {
7
+ runtime : 'nodejs14.x'
8
+ } ) ;
9
+
10
+ new MyStack ( app , 'my-stack' ) ;
11
+
12
+ // Add more stacks
13
+ }
Original file line number Diff line number Diff line change
1
+ import { Template } from 'aws-cdk-lib/assertions' ;
2
+ import * as sst from '@serverless-stack/resources' ;
3
+ import MyStack from '../stacks/MyStack' ;
4
+
5
+ test ( 'Test Stack' , ( ) => {
6
+ const app = new sst . App ( ) ;
7
+ // WHEN
8
+ const stack = new MyStack ( app , 'test-stack' ) ;
9
+ // THEN
10
+ const template = Template . fromStack ( stack ) ;
11
+ template . resourceCountIs ( 'AWS::Lambda::Function' , 1 ) ;
12
+ } ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "extends" : " @tsconfig/node14" ,
3
+ "include" : [" stacks" , " src" ]
4
+ }
You can’t perform that action at this time.
0 commit comments