Skip to content

Commit

Permalink
Add in experimental support for cloudformation
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Feb 22, 2022
1 parent 16a1884 commit 8c0028a
Show file tree
Hide file tree
Showing 9 changed files with 475 additions and 49 deletions.
1 change: 1 addition & 0 deletions LANGUAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Ceylon (ceylon)
Clojure (clj,cljc)
ClojureScript (cljs)
Closure Template (soy)
CloudFormation (yaml,yml)
CMake (cmake,cmakelists.txt)
COBOL (cob,cbl,ccp,cobol,cpy)
CodeQL (ql,qll)
Expand Down
115 changes: 71 additions & 44 deletions SCC-OUTPUT-REPORT.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<tbody><tr>
<th>Go</th>
<th>36</th>
<th>9094</th>
<th>1445</th>
<th>429</th>
<th>7220</th>
<th>1481</th>
<th>358069</th>
<th>9144</th>
<th>1454</th>
<th>441</th>
<th>7249</th>
<th>1494</th>
<th>360579</th>
</tr><tr>
<th>Java</th>
<th>24</th>
Expand All @@ -39,12 +39,12 @@
</tr><tr>
<th>Markdown</th>
<th>11</th>
<th>1348</th>
<th>1349</th>
<th>319</th>
<th>0</th>
<th>1029</th>
<th>1030</th>
<th>0</th>
<th>54998</th>
<th>55024</th>
</tr><tr>
<th>Python</th>
<th>10</th>
Expand All @@ -54,6 +54,15 @@
<th>321</th>
<th>27</th>
<th>10706</th>
</tr><tr>
<th>YAML</th>
<th>7</th>
<th>662</th>
<th>51</th>
<th>22</th>
<th>589</th>
<th>0</th>
<th>12520</th>
</tr><tr>
<th>CSS</th>
<th>5</th>
Expand All @@ -72,15 +81,6 @@
<th>43</th>
<th>0</th>
<th>3425</th>
</tr><tr>
<th>YAML</th>
<th>5</th>
<th>103</th>
<th>19</th>
<th>20</th>
<th>64</th>
<th>0</th>
<th>2514</th>
</tr><tr>
<th>gitignore</th>
<th>4</th>
Expand All @@ -98,7 +98,7 @@
<th>85</th>
<th>879</th>
<th>99</th>
<th>39752</th>
<th>39778</th>
</tr><tr>
<th>C#</th>
<th>2</th>
Expand All @@ -108,6 +108,24 @@
<th>492</th>
<th>26</th>
<th>19739</th>
</tr><tr>
<th>HTML</th>
<th>2</th>
<th>1234</th>
<th>0</th>
<th>0</th>
<th>1234</th>
<th>0</th>
<th>18024</th>
</tr><tr>
<th>JSON</th>
<th>2</th>
<th>7526</th>
<th>0</th>
<th>0</th>
<th>7526</th>
<th>0</th>
<th>114816</th>
</tr><tr>
<th>JavaServer Pages</th>
<th>2</th>
Expand Down Expand Up @@ -234,6 +252,15 @@
<th>1</th>
<th>0</th>
<th>6</th>
</tr><tr>
<th>CSV</th>
<th>1</th>
<th>67</th>
<th>0</th>
<th>0</th>
<th>67</th>
<th>0</th>
<th>1786</th>
</tr><tr>
<th>Clojure</th>
<th>1</th>
Expand All @@ -243,6 +270,15 @@
<th>1</th>
<th>0</th>
<th>9</th>
</tr><tr>
<th>CloudFormation</th>
<th>1</th>
<th>150</th>
<th>16</th>
<th>1</th>
<th>133</th>
<th>0</th>
<th>4697</th>
</tr><tr>
<th>Coq</th>
<th>1</th>
Expand Down Expand Up @@ -378,24 +414,6 @@
<th>10</th>
<th>0</th>
<th>245</th>
</tr><tr>
<th>HTML</th>
<th>1</th>
<th>617</th>
<th>0</th>
<th>0</th>
<th>617</th>
<th>0</th>
<th>9000</th>
</tr><tr>
<th>JSON</th>
<th>1</th>
<th>7480</th>
<th>0</th>
<th>0</th>
<th>7480</th>
<th>0</th>
<th>104165</th>
</tr><tr>
<th>Korn Shell</th>
<th>1</th>
Expand Down Expand Up @@ -495,6 +513,15 @@
<th>0</th>
<th>0</th>
<th>0</th>
</tr><tr>
<th>SQL</th>
<th>1</th>
<th>198</th>
<th>0</th>
<th>0</th>
<th>198</th>
<th>0</th>
<th>23235</th>
</tr><tr>
<th>Sieve</th>
<th>1</th>
Expand Down Expand Up @@ -606,12 +633,12 @@
</tr></tbody>
<tfoot><tr>
<th>Total</th>
<th>176</th>
<th>26945</th>
<th>3043</th>
<th>1765</th>
<th>22137</th>
<th>2467</th>
<th>1815827</th>
<th>183</th>
<th>28633</th>
<th>3100</th>
<th>1780</th>
<th>23753</th>
<th>2480</th>
<th>1877788</th>
</tr></tfoot>
</table></body></html>
150 changes: 150 additions & 0 deletions examples/language/cloudformation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
AWSTemplateFormatVersion: '2010-09-09'

Description: AWS lambda search - implementation

Resources:

# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html

LambdaFunctionController:
Type: AWS::Lambda::Function
Properties:
FunctionName: aws-lambda-search-controller
Handler: main
Role: !GetAtt LambdaServiceRole.Arn
MemorySize: 3538
Code:
S3Bucket: !Sub "aws-lambda-search-lambda-${AWS::AccountId}"
S3Key: controller.zip
Runtime: go1.x
Timeout: 10 # needs to be high to account for the cold start time otherwise it never runs

LambdaFunctionController2:
Type: AWS::Lambda::Function
Properties:
FunctionName: aws-lambda-search-controller-2
Handler: main
Role: !GetAtt LambdaServiceRole.Arn
MemorySize: 3538
Code:
S3Bucket: !Sub "aws-lambda-search-lambda-${AWS::AccountId}"
S3Key: controller.zip
Runtime: go1.x
Timeout: 10 # needs to be high to account for the cold start time otherwise it never runs

LambdaFunctionNewsFetcher:
Type: AWS::Lambda::Function
Properties:
FunctionName: newsfetcher
Handler: main
Role: !GetAtt LambdaServiceRole.Arn
MemorySize: 1024
Code:
S3Bucket: !Sub "aws-lambda-search-lambda-${AWS::AccountId}"
S3Key: newsfetcher.zip
Runtime: go1.x
Timeout: 10 # needs to be high to account for the cold start time otherwise it never runs

CronEvent: #logical name of the resource
Type: AWS::Events::Rule
Properties:
ScheduleExpression: rate(15 minutes)
Targets:
- Arn:
Fn::GetAtt: [ LambdaFunctionNewsFetcher , "Arn" ] #reference the lambda function by its arn
Id:
Ref: LambdaFunctionNewsFetcher

HttpApi:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: aws-lambda-api-search
Description: "aws lambda search API"
ProtocolType: HTTP
RouteSelectionExpression: "$request.method $request.path"
Version: "1.0"
DisableExecuteApiEndpoint: false
CorsConfiguration:
AllowMethods:
- GET
- POST
- PUT
- DELETE
AllowOrigins:
- "*"
AllowHeaders:
- "*"

HttpApiLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "aws-lambda-search-api-gateway-logs"
RetentionInDays: 1

HttpApiStage:
Type: AWS::ApiGatewayV2::Stage
Properties:
ApiId: !Ref HttpApi
AutoDeploy: true
StageName: "$default"
AccessLogSettings:
DestinationArn: !GetAtt HttpApiLogGroup.Arn
Format: '{"requestId":"$context.requestId","ip": "$context.identity.sourceIp","requestTime":"$context.requestTime","httpMethod":"$context.httpMethod","routeKey":"$context.routeKey","status":"$context.status","protocol":"$context.protocol","responseLength":"$context.responseLength","userId":"$context.authorizer.userId","userRole":"$context.authorizer.userRole","sessionId":"$context.authorizer.sessionId"}'

HttpSearchRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref HttpApi
AuthorizationType: NONE
RouteKey: "GET /search"
Target: !Sub "integrations/${HttpApiIntegration}"

HttpApiIntegration:
DependsOn:
- LambdaFunctionController
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref HttpApi
ConnectionType: INTERNET
IntegrationMethod: POST
IntegrationType: AWS_PROXY
IntegrationUri: !GetAtt LambdaFunctionController.Arn
PayloadFormatVersion: "2.0"

HttpSearchRoute2:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref HttpApi
AuthorizationType: NONE
RouteKey: "GET /search2"
Target: !Sub "integrations/${HttpApiIntegration2}"

HttpApiIntegration2:
DependsOn:
- LambdaFunctionController2
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref HttpApi
ConnectionType: INTERNET
IntegrationMethod: POST
IntegrationType: AWS_PROXY
IntegrationUri: !GetAtt LambdaFunctionController2.Arn
PayloadFormatVersion: "2.0"

LambdaAPIGatewayPermission:
DependsOn:
- HttpApi
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt LambdaFunctionController.Arn
Principal: apigateway.amazonaws.com

LambdaAPIGatewayPermission2:
DependsOn:
- HttpApi
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt LambdaFunctionController2.Arn
Principal: apigateway.amazonaws.com
Loading

0 comments on commit 8c0028a

Please sign in to comment.