Skip to content

Commit 21f4993

Browse files
committed
npx create-serverless-stack@latest heft-serverless-stack-tutorial --language typescript
1 parent b43ae4b commit 21f4993

File tree

9 files changed

+135
-0
lines changed

9 files changed

+135
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prod
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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).
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "heft-serverless-stack-tutorial",
3+
"region": "us-east-1",
4+
"main": "stacks/index.ts"
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "@tsconfig/node14",
3+
"include": ["stacks", "src"]
4+
}

0 commit comments

Comments
 (0)