Skip to content

Upgrading to Node 18 and Serverless 3.38.0 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ As with most AWS services you will incur costs for usage. For this CloudFormatio
* The serverless framework file that defines AWS Lambda Functions and the events that trigger them along with any resources they require.
* buildspec-dev.yml ~ buildspec-stg.yml ~ buildspec-prod.yml
* File or files CodeBuild reads to understand build commands and related settings. There are three representing typical DEV STAGE and PROD environments.
* deploy.sh
* Instructions for AWS CodePipeline to deploy the chosen environment

## Deploy the CloudFormation Template

Expand Down Expand Up @@ -87,10 +85,8 @@ In the *AWS Management Console* you should be able to *verify* the following hav

## Workflow

The workflow is as follows, the Github repo/branch you designated with your Serverless code will be sourced initially and upon commits, which then will trigger a AWS CodeBuild project that will package the code (you can add linting here), and send the result to another AWS CodeBuild project that will deploy the code using a deploy script.
The workflow is as follows, the Github repo/branch you designated with your Serverless code will be sourced initially and upon commits, which then will trigger a AWS CodeBuild project that will package the code (you can add linting here), and send the result to another AWS CodeBuild project that will deploy the code using serverless framework.

If you used this repository as a test you can go to CloudFormation and see two templates one has "aws-serverless-express-application" in the name if you select it and look at the "Outputs" tab you will see "ServiceEndpoint" with a URL click on it and you will get a "Hello World!" message.

Anytime you commit code to the repo/branch you specified it will trigger a new build and deploy it. This will be more relevant when you use it for your own repo/branch and not the test one since you don't have access to commit to this repository.


17 changes: 5 additions & 12 deletions buildspec-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,25 @@ version: 0.2
phases:
install:
commands:
#- rm package-lock.json
- npm install --silent --progress=false -g npm
- n 18.19.0

## Dependencies
- npm install --silent --progress-false
- npm --version
- npm install --silent --progress=false -g serverless
- npm install --silent --progress=false -g [email protected]
- npm install --silent --save–dev serverless-stack-output

build:
commands:
## Integration test environment
#- serverless deploy --stage test -v
- mkdir artifacts
- mkdir artifacts/stg
- serverless package --package artifacts/dev --stage dev -v
## Tests

post_build:
commands:
## Remove integration testing environment
#- serverless remove --stage test -v
## Post build commands

artifacts:
files:
- artifacts/**/*
- serverless.yml
- deploy.sh
- index.js
- package.json
- package-lock.json
17 changes: 5 additions & 12 deletions buildspec-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,25 @@ version: 0.2
phases:
install:
commands:
#- rm package-lock.json
- npm install --silent --progress=false -g npm
- n 18.19.0

## Dependencies
- npm install --silent --progress-false
- npm --version
- npm install --silent --progress=false -g serverless
- npm install --silent --progress=false -g [email protected]
- npm install --silent --save–dev serverless-stack-output

build:
commands:
## Integration test environment
#- serverless deploy --stage test -v
- mkdir artifacts
- mkdir artifacts/prod
- serverless package --package artifacts/prod --stage prod -v
## Tests

post_build:
commands:
## Remove integration testing environment
#- serverless remove --stage test -v
## Post build commands

artifacts:
files:
- artifacts/**/*
- serverless.yml
- deploy.sh
- index.js
- package.json
- package-lock.json
17 changes: 5 additions & 12 deletions buildspec-stg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,25 @@ version: 0.2
phases:
install:
commands:
#- rm package-lock.json
- npm install --silent --progress=false -g npm
- n 18.19.0

## Dependencies
- npm install --silent --progress-false
- npm --version
- npm install --silent --progress=false -g serverless
- npm install --silent --progress=false -g [email protected]
- npm install --silent --save–dev serverless-stack-output

build:
commands:
## Integration test environment
#- serverless deploy --stage test -v
- mkdir artifacts
- mkdir artifacts/stg
- serverless package --package artifacts/stg --stage stg -v
## Tests

post_build:
commands:
## Remove integration testing environment
#- serverless remove --stage test -v
## Post build commands

artifacts:
files:
- artifacts/**/*
- serverless.yml
- deploy.sh
- index.js
- package.json
- package-lock.json
11 changes: 0 additions & 11 deletions deploy.sh

This file was deleted.

20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 18 additions & 50 deletions serverless-code-pipeline-cf-template.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright [2018] [Phil Chen]
# Copyright [2024] [Phil Chen]

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,8 +38,8 @@ Parameters:

GitHubOAuthToken:
Type: String
Default: GitHub OAuthToken Here
Description: CodePipeline requires an OAuthToken
NoEcho: true
Description: CodePipeline requires an GitHub OAuthToken

Resources:

Expand Down Expand Up @@ -80,58 +80,22 @@ Resources:
Statement:
Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
- logs:DescribeLogGroups
- logs:FilterLogEvents
- logs:DescribeLogStreams
- logs:DeleteLogGroup
- s3:putObject
- s3:getObject
- codebuild:*
- 'cloudformation:List*'
- 'cloudformation:Get*'
- 'cloudformation:PreviewStackUpdate'
- 'cloudformation:ValidateTemplate'
- 'cloudformation:CreateStack'
- 'cloudformation:CreateUploadBucket'
- 'cloudformation:DeleteStack'
- 'cloudformation:Describe*'
- 'cloudformation:UpdateStack'
- 'lambda:Get*'
- 'lambda:List*'
- 'lambda:CreateFunction'
- 'lambda:AddPermission'
- 'lambda:CreateAlias'
- 'lambda:DeleteFunction'
- 'lambda:InvokeFunction'
- 'lambda:PublishVersion'
- 'lambda:RemovePermission'
- 'lambda:Update*'
- 'apigateway:GET'
- 'apigateway:POST'
- 'apigateway:PUT'
- 'apigateway:DELETE'
- 's3:CreateBucket'
- 's3:DeleteBucket'
- 's3:ListBucket'
- 's3:ListBucketVersions'
- 's3:PutObject'
- 's3:GetObject'
- 's3:DeleteObject'
- 'logs:*'
- 'codebuild:*'
- 'cloudformation:*'
- 'lambda:*'
- 'apigateway:*'
- 's3:*'
- 'iam:PassRole'
- 'kinesis:*'
- 'iam:GetRole'
- 'iam:CreateRole'
- 'iam:PutRolePolicy'
- 'iam:DeleteRolePolicy'
- 'iam:DeleteRole'
- 'cloudwatch:GetMetricStatistics'
- 'iam:TagRole'
- 'events:Put*'
- 'events:Remove*'
- 'events:Delete*'
- 'dynamodb:*'
Resource: "*"
Roles:
- !Ref CodeBuildRole
Expand Down Expand Up @@ -175,7 +139,7 @@ Resources:
Environment:
Type: "LINUX_CONTAINER"
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/nodejs:10.1.0
Image: aws/codebuild/standard:7.0
Artifacts:
Type: CODEPIPELINE

Expand All @@ -193,15 +157,19 @@ Resources:
phases:
build:
commands:
- bash deploy.sh
- n 18.19.0
- npm install --silent --progress-false
- npm install --silent --progress=false -g [email protected]
- npm install --silent --save–dev serverless-stack-output
- serverless deploy
Environment:
Type: "LINUX_CONTAINER"
ComputeType: BUILD_GENERAL1_SMALL
EnvironmentVariables:
- Name: env
Type: PLAINTEXT
Value: !Ref Environment
Image: aws/codebuild/nodejs:10.1.0
Image: aws/codebuild/standard:7.0
Artifacts:
Type: CODEPIPELINE

Expand Down Expand Up @@ -236,7 +204,7 @@ Resources:
OutputArtifacts:
- Name: TheSourceCode

# Stage 2: Build using Serverless Framework
# Stage 2: Run Your Tests
- Name: TestBuild
Actions:
- Name: Test-Build
Expand Down
2 changes: 1 addition & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ functions:
handler: index.handler
events:
- http: ANY /
- http: 'ANY {proxy+}'
- http: 'ANY /{proxy+}'