From 06978296f5b8911e4ef2ee17d46baab67243b2c2 Mon Sep 17 00:00:00 2001 From: rogerwelin Date: Tue, 5 May 2020 16:56:35 +0200 Subject: [PATCH] fixes in readme, for nodejs --- .gitignore | 1 + tmpl-languages.go | 7 ++++--- tmpl-readme.go | 16 +++++++--------- tmpl-sam.go | 9 +++++++-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 2ab69b0..0488d0e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ src +apa/ apigw.yml swagger-api.yml main diff --git a/tmpl-languages.go b/tmpl-languages.go index 8da90d3..36528f7 100644 --- a/tmpl-languages.go +++ b/tmpl-languages.go @@ -7,15 +7,16 @@ const nodeFunction = ` exports.handler = function(event, context) { let msg = { - msg: 'hello world' + statusCode: 200, + body: 'hello world' } - context.succeed(JSON.stringify(msg)); + context.succeed(msg); }; ` const packageJson = ` { - "name": "hello world", + "name": "helloworld", "version": "1.0.0", "description": "", "main": "index.js", diff --git a/tmpl-readme.go b/tmpl-readme.go index 21152f0..4b2e76f 100644 --- a/tmpl-readme.go +++ b/tmpl-readme.go @@ -23,17 +23,15 @@ $ pip install --user aws-sam-cli $ sam build --template-file apigw.yml ` + "```" + ` -### Package the Project +### Package & Deploy the Project ` + "```" + `bash -$ sam package --template-file apigw.yml --output-template-file out.yaml --s3-bucket {Your-S3-bucket} +$ sam deploy --guided ` + "```" + ` -### Deploy the API -` + "```" + `bash -$ aws cloudformation deploy --template-file ./out.yaml --stack-name your-api-project --capabilities CAPABILITY_IAM -` + "```" + ` - -Go to the AWS console > Cloudformation. Make sure the Cloudformations stack finishes. Take a look at the output to get the URL of your newly created API project. Either curl the address at the /hello endpoint or run the endpoint directly in the API Gateway console. - +The --guided flag will set up all needed IAM roles and a S3 bucket and finally will set upp all needed AWS resources and deploy the code. +Check the Outputs from the command line and grab the URL. Now do a curl against URL/helloworld +{{ if and (eq .APIEndpoints "private") }} +However since this is a private api, you need to do the curl from within your VPC +{{ end }} ` diff --git a/tmpl-sam.go b/tmpl-sam.go index 8f0f595..87cad32 100644 --- a/tmpl-sam.go +++ b/tmpl-sam.go @@ -10,6 +10,11 @@ Parameters: VPCId: Description: ID of the VPC ID Type: AWS::EC2::VPC::Id + VPCCidr: + Description: Valid CIDR of the VPC + Type: String + AllowedPattern: ^([0-9]{1,3}\.){3}[0-9]{1,3}(\/([0-9]|[1-2][0-9]|3[0-2]))?$ + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x SubnetIDs: Description: A list/array of Subnet IDs Type: List @@ -46,7 +51,7 @@ Resources: VpcId: !Ref VPCId SecurityGroupIngress: - IpProtocol: tcp - CidrIp: 172.31.190.0/24 + CidrIp: !Ref VPCCidr FromPort: 0 ToPort: 65535 @@ -130,7 +135,7 @@ Resources: CodeUri: src/{{ .LambdaFunctionName }}/app/ {{ if and (eq .Language "python")}}Handler: app.handler Runtime: python3.7{{ end }}{{ if and (eq .Language "ruby")}}Handler: app.handler - Runtime: ruby2.5{{ end }}{{ if and (eq .Language "node")}}Handler: index.js + Runtime: ruby2.5{{ end }}{{ if and (eq .Language "node")}}Handler: index.handler Runtime: nodejs10.x{{ end }}{{ if and (eq .Language "go")}}Handler: helloworld Runtime: go1.x{{ end }}{{ if and (eq .Language "java")}}Handler: com.api.HelloWorld Runtime: java8{{ end }}