Skip to content

Commit 433fdf8

Browse files
authored
Merge pull request #5 from fabidick22/aws-sam-template
AWS SAM template
2 parents dd5b039 + 2cbc567 commit 433fdf8

File tree

8 files changed

+383
-0
lines changed

8 files changed

+383
-0
lines changed

.gitignore

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### SAM template
3+
# gitignore template for AWS Serverless Application Model project
4+
# website: https://docs.aws.amazon.com/serverless-application-model
5+
6+
# Ignore build folder
7+
.aws-sam/
8+
9+
### Node template
10+
# Logs
11+
logs
12+
*.log
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
16+
lerna-debug.log*
17+
18+
# Diagnostic reports (https://nodejs.org/api/report.html)
19+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
20+
21+
# Runtime data
22+
pids
23+
*.pid
24+
*.seed
25+
*.pid.lock
26+
27+
# Directory for instrumented libs generated by jscoverage/JSCover
28+
lib-cov
29+
30+
# Coverage directory used by tools like istanbul
31+
coverage
32+
*.lcov
33+
34+
# nyc test coverage
35+
.nyc_output
36+
37+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
38+
.grunt
39+
40+
# Bower dependency directory (https://bower.io/)
41+
bower_components
42+
43+
# node-waf configuration
44+
.lock-wscript
45+
46+
# Compiled binary addons (https://nodejs.org/api/addons.html)
47+
build/Release
48+
49+
# Dependency directories
50+
node_modules/
51+
jspm_packages/
52+
53+
# Snowpack dependency directory (https://snowpack.dev/)
54+
web_modules/
55+
56+
# TypeScript cache
57+
*.tsbuildinfo
58+
59+
# Optional npm cache directory
60+
.npm
61+
62+
# Optional eslint cache
63+
.eslintcache
64+
65+
# Microbundle cache
66+
.rpt2_cache/
67+
.rts2_cache_cjs/
68+
.rts2_cache_es/
69+
.rts2_cache_umd/
70+
71+
# Optional REPL history
72+
.node_repl_history
73+
74+
# Output of 'npm pack'
75+
*.tgz
76+
77+
# Yarn Integrity file
78+
.yarn-integrity
79+
80+
# dotenv environment variables file
81+
.env
82+
.env.test
83+
84+
# parcel-bundler cache (https://parceljs.org/)
85+
.cache
86+
.parcel-cache
87+
88+
# Next.js build output
89+
.next
90+
out
91+
92+
# Nuxt.js build / generate output
93+
.nuxt
94+
dist
95+
96+
# Gatsby files
97+
.cache/
98+
# Comment in the public line in if your project uses Gatsby and not Next.js
99+
# https://nextjs.org/blog/next-9-1#public-directory-support
100+
# public
101+
102+
# vuepress build output
103+
.vuepress/dist
104+
105+
# Serverless directories
106+
.serverless/
107+
108+
# FuseBox cache
109+
.fusebox/
110+
111+
# DynamoDB Local files
112+
.dynamodb/
113+
114+
# TernJS port file
115+
.tern-port
116+
117+
# Stores VSCode versions used for testing VSCode extensions
118+
.vscode-test
119+
120+
# yarn v2
121+
.yarn/cache
122+
.yarn/unplugged
123+
.yarn/build-state.yml
124+
.yarn/install-state.gz
125+
.pnp.*
126+
127+
### JetBrains template
128+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
129+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
130+
131+
# User-specific stuff
132+
.idea/**/workspace.xml
133+
.idea/**/tasks.xml
134+
.idea/**/usage.statistics.xml
135+
.idea/**/dictionaries
136+
.idea/**/shelf
137+
138+
# Generated files
139+
.idea/**/contentModel.xml
140+
141+
# Sensitive or high-churn files
142+
.idea/**/dataSources/
143+
.idea/**/dataSources.ids
144+
.idea/**/dataSources.local.xml
145+
.idea/**/sqlDataSources.xml
146+
.idea/**/dynamic.xml
147+
.idea/**/uiDesigner.xml
148+
.idea/**/dbnavigator.xml
149+
150+
# Gradle
151+
.idea/**/gradle.xml
152+
.idea/**/libraries
153+
154+
# Gradle and Maven with auto-import
155+
# When using Gradle or Maven with auto-import, you should exclude module files,
156+
# since they will be recreated, and may cause churn. Uncomment if using
157+
# auto-import.
158+
# .idea/artifacts
159+
# .idea/compiler.xml
160+
# .idea/jarRepositories.xml
161+
# .idea/modules.xml
162+
# .idea/*.iml
163+
# .idea/modules
164+
# *.iml
165+
# *.ipr
166+
167+
# CMake
168+
cmake-build-*/
169+
170+
# Mongo Explorer plugin
171+
.idea/**/mongoSettings.xml
172+
173+
# File-based project format
174+
*.iws
175+
176+
# IntelliJ
177+
out/
178+
179+
# mpeltonen/sbt-idea plugin
180+
.idea_modules/
181+
182+
# JIRA plugin
183+
atlassian-ide-plugin.xml
184+
185+
# Cursive Clojure plugin
186+
.idea/replstate.xml
187+
188+
# Crashlytics plugin (for Android Studio and IntelliJ)
189+
com_crashlytics_export_strings.xml
190+
crashlytics.properties
191+
crashlytics-build.properties
192+
fabric.properties
193+
194+
# Editor-based Rest Client
195+
.idea/httpRequests
196+
197+
# Android studio 3.1+ serialized cache file
198+
.idea/caches/build_file_checksums.ser
199+

events/event.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"body": "{\"message\": \"hello world\"}",
3+
"resource": "/{proxy+}",
4+
"path": "/path/to/resource",
5+
"httpMethod": "POST",
6+
"isBase64Encoded": false,
7+
"queryStringParameters": {
8+
"foo": "bar"
9+
},
10+
"pathParameters": {
11+
"proxy": "/path/to/resource"
12+
},
13+
"stageVariables": {
14+
"baz": "qux"
15+
},
16+
"headers": {
17+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
18+
"Accept-Encoding": "gzip, deflate, sdch",
19+
"Accept-Language": "en-US,en;q=0.8",
20+
"Cache-Control": "max-age=0",
21+
"CloudFront-Forwarded-Proto": "https",
22+
"CloudFront-Is-Desktop-Viewer": "true",
23+
"CloudFront-Is-Mobile-Viewer": "false",
24+
"CloudFront-Is-SmartTV-Viewer": "false",
25+
"CloudFront-Is-Tablet-Viewer": "false",
26+
"CloudFront-Viewer-Country": "US",
27+
"Host": "1234567890.execute-api.us-east-1.amazonaws.com",
28+
"Upgrade-Insecure-Requests": "1",
29+
"User-Agent": "Custom User Agent String",
30+
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
31+
"X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
32+
"X-Forwarded-For": "127.0.0.1, 127.0.0.2",
33+
"X-Forwarded-Port": "443",
34+
"X-Forwarded-Proto": "https"
35+
},
36+
"requestContext": {
37+
"accountId": "123456789012",
38+
"resourceId": "123456",
39+
"stage": "prod",
40+
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
41+
"requestTime": "09/Apr/2015:12:34:56 +0000",
42+
"requestTimeEpoch": 1428582896000,
43+
"identity": {
44+
"cognitoIdentityPoolId": null,
45+
"accountId": null,
46+
"cognitoIdentityId": null,
47+
"caller": null,
48+
"accessKey": null,
49+
"sourceIp": "127.0.0.1",
50+
"cognitoAuthenticationType": null,
51+
"cognitoAuthenticationProvider": null,
52+
"userArn": null,
53+
"userAgent": "Custom User Agent String",
54+
"user": null
55+
},
56+
"path": "/prod/path/to/resource",
57+
"resourcePath": "/{proxy+}",
58+
"httpMethod": "POST",
59+
"apiId": "1234567890",
60+
"protocol": "HTTP/1.1"
61+
}
62+
}

samconfig.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version = 0.1
2+
[default]
3+
[default.deploy]
4+
[default.deploy.parameters]
5+
region = "us-east-2"
6+
confirm_changeset = true
7+
capabilities = "CAPABILITY_IAM"
8+
parameter_overrides = "Environment=\"stage\""
9+

src/handlers/hello-world/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/*

src/handlers/hello-world/app.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
let response;
3+
4+
exports.lambdaHandler = async (event, context) => {
5+
try {
6+
response = {
7+
'statusCode': 200,
8+
'body': JSON.stringify({
9+
message: 'hello world',
10+
// location: ret.data.trim()
11+
})
12+
}
13+
} catch (err) {
14+
console.log(err);
15+
return err;
16+
}
17+
18+
return response
19+
};

src/handlers/hello-world/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "hello_world",
3+
"version": "1.0.0",
4+
"description": "hello world sample for NodeJS",
5+
"main": "app.js",
6+
"repository": "",
7+
"author": "SAM CLI",
8+
"license": "MIT",
9+
"dependencies": {},
10+
"scripts": {
11+
"test": "mocha tests/unit"
12+
},
13+
"devDependencies": {
14+
"chai": "^4.2.0",
15+
"mocha": "^6.1.4"
16+
}
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const app = require('../../app.js');
4+
const chai = require('chai');
5+
const expect = chai.expect;
6+
var event, context;
7+
8+
describe('Tests index', function () {
9+
it('verifies successful response', async () => {
10+
const result = await app.lambdaHandler(event, context)
11+
12+
expect(result).to.be.an('object');
13+
expect(result.statusCode).to.equal(200);
14+
expect(result.body).to.be.an('string');
15+
16+
let response = JSON.parse(result.body);
17+
18+
expect(response).to.be.an('object');
19+
expect(response.message).to.be.equal("hello world");
20+
// expect(response.location).to.be.an("string");
21+
});
22+
});

template.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
Description: >
4+
DevOps
5+
6+
Sample SAM Template for aws-serverless-devops
7+
8+
9+
Parameters:
10+
Environment:
11+
Type: String
12+
AllowedValues:
13+
- stage
14+
- prod
15+
16+
Conditions:
17+
ProdCondition:
18+
!Equals [!Ref Environment, prod]
19+
20+
Globals:
21+
Function:
22+
Runtime: nodejs12.x
23+
Tracing: Active
24+
MemorySize: 128
25+
Timeout: 100
26+
27+
Resources:
28+
ServerlessHTTPApi:
29+
Type: AWS::Serverless::HttpApi
30+
31+
HelloWorldFunction:
32+
Type: AWS::Serverless::Function
33+
Properties:
34+
FunctionName: !Sub "${AWS::StackName}-helloWorldFunction"
35+
CodeUri: src/handlers/hello-world/
36+
Handler: app.lambdaHandler
37+
Events:
38+
HelloWorld:
39+
Type: HttpApi
40+
Properties:
41+
ApiId: !Ref ServerlessHTTPApi
42+
Path: /hello
43+
Method: get
44+
45+
Outputs:
46+
HelloWorldApi:
47+
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
48+
Value: !Sub "https://${ServerlessHTTPApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
49+
HelloWorldFunction:
50+
Description: "Hello World Lambda Function ARN"
51+
Value: !GetAtt HelloWorldFunction.Arn
52+
HelloWorldFunctionIamRole:
53+
Description: "Implicit IAM Role created for Hello World function"
54+
Value: !GetAtt HelloWorldFunctionRole.Arn

0 commit comments

Comments
 (0)