├── .gitignore ├── docker └── Dockerfile ├── serverless.cbl ├── index.js ├── app_spec_template.yml ├── package.json ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | cobolambda.log 2 | 3 | # Node.js 4 | npm-debug.log* 5 | node_modules 6 | 7 | # SAM 8 | app_spec.yml 9 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | 3 | RUN apt-get update && \ 4 | apt-get install -y open-cobol && \ 5 | apt-get clean && \ 6 | rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 7 | 8 | WORKDIR /src 9 | -------------------------------------------------------------------------------- /serverless.cbl: -------------------------------------------------------------------------------- 1 | IDENTIFICATION DIVISION. 2 | PROGRAM-ID. COBOLAMBDA. 3 | ENVIRONMENT DIVISION. 4 | DATA DIVISION. 5 | PROCEDURE DIVISION. 6 | DISPLAY "Hello Serverless World!". 7 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | let cobolscript = require('cobolscript') 4 | let SCRIPT = './serverless.cbl' 5 | 6 | const hookConsoleLog = (logs) => { console.log = (d) => logs.push(d) } 7 | 8 | exports.handler = (event, context, callback) => { 9 | var logs = [] 10 | hookConsoleLog(logs) 11 | 12 | var program = cobolscript.compileProgramFile(SCRIPT) 13 | program.run(cobolscript.getRuntime()) 14 | callback(null, { statusCode: 200, body: logs.join('\n') }) 15 | } 16 | -------------------------------------------------------------------------------- /app_spec_template.yml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: AWS::Serverless-2016-10-31 3 | Resources: 4 | CobolFunction: 5 | Type: AWS::Serverless::Function 6 | Properties: 7 | Handler: index.handler 8 | Runtime: nodejs4.3 9 | CodeUri: . 10 | Events: 11 | GetResource: 12 | Type: Api 13 | Properties: 14 | Path: /cobolambda 15 | Method: get 16 | Outputs: 17 | CobolFunction: 18 | Value: !Ref CobolFunction 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cobolambda", 3 | "version": "1.0.0", 4 | "description": "Cobol on AWS Lambda", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/toricls/cobolambda.git" 12 | }, 13 | "author": "toricls", 14 | "license": "MIT", 15 | "homepage": "https://github.com/toricls/cobolambda", 16 | "readme": "README.md", 17 | "dependencies": { 18 | "cobolscript": "ajlopez/CobolScript" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 toricls 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cobolambda 2 | 3 | Serverless COBOL on AWS Lambda. 4 | 5 | ## Prerequisites 6 | 7 | - AWS Lambda 8 | - Amazon API Gateway 9 | - AWS CloudFormation 10 | - Node.js + npm 11 | 12 | ## Overview 13 | ![Overview](https://github.com/toricls/cobolambda/wiki/res/overview.png) 14 | 15 | ## Usage 16 | 17 | Don't. 18 | 19 | ## Configure & Deploy 20 | 21 | We need both npm and [aws-cli](https://aws.amazon.com/cli/) to configure and deploy. 22 | 23 | ### Create a S3 bucket to store an app package 24 | 25 | ``` 26 | $ export COBOLAMBDA_S3BUCKET= 27 | $ aws s3api create-bucket --bucket $COBOLAMBDA_S3BUCKET 28 | ``` 29 | 30 | ### Install dependencies 31 | 32 | ``` 33 | $ npm install 34 | ``` 35 | 36 | ### Package 37 | 38 | ``` 39 | $ aws cloudformation package --template-file app_spec_template.yml --output-template-file app_spec.yml --s3-bucket $COBOLAMBDA_S3BUCKET 40 | ``` 41 | 42 | ### Deploy 43 | 44 | ``` 45 | $ aws cloudformation deploy --template-file app_spec.yml --stack-name cobolambda --capabilities CAPABILITY_IAM 46 | ``` 47 | 48 | ## Run 49 | 50 | ``` 51 | $ export REST_API_ID=$( aws cloudformation describe-stack-resource --stack-name cobolambda --logical-resource-id ServerlessRestApi --query "StackResourceDetail.PhysicalResourceId" --output text ) 52 | 53 | $ curl https://$REST_API_ID.execute-api..amazonaws.com/Prod/cobolambda 54 | ``` 55 | 56 | ## Writing & Compiling COBOL on Docker container 57 | 58 | ``` 59 | $ docker run -it --rm -v $(pwd):/src toricls/gnucobol:latest bash 60 | root@xxxxxxxxxxxx:/src# cobc --help 61 | ``` 62 | 63 | ## Licence 64 | 65 | [MIT](LICENCE) 66 | 67 | ## Author 68 | 69 | [toricls](https://github.com/toricls) 70 | --------------------------------------------------------------------------------