Skip to content

Serverless application with CI/CD pipeline written in go using AWS CDK

Notifications You must be signed in to change notification settings

bosorawis/go-cdk-pipeline

Repository files navigation

Serverless application with CI/CD in Go

Installation list

NOTES

This demo only supports single region/account deployment. The Pipeline construct CAN support multi-region multi-account pipeline but that requires additional setup and resources including KMS key which does not have a free tier.

Structure

.
├── infastructure           # cdk code defining all our infrastructure written in go
├── goapp                   # application code for lambda serverless 

Preparing

Install and Configure AWS CDK

Install

npm install -g aws-cdk
cdk --version

Bootstrap your AWS account

cdk bootstrap 

more information about cdk bootstrap here

Create Github connection for CodePipeline

CodePipeline will need a way to access your Github account. You can follow the official guide here or

To create Github connection:
  1. Browse to AWS Developer console at https://console.aws.amazon.com/codesuite/settings/connections
  2. Go to Settings > Connections
  3. Click Create Connection and follow the prompt

Deploying the pipeline and application

Clone this repo and edit the following file to use your Github information

// infrastructure/pipeline.go
    githubSource := awscodepipelineactions.NewCodeStarConnectionsSourceAction(&awscodepipelineactions.CodeStarConnectionsSourceActionProps{
		ActionName: jsii.String("github"),
		Owner: jsii.String("<your-github-account>"),
		Repo: jsii.String("<your-github-repo>"),
		Branch: jsii.String("<branch>"),
		Output: sourceArtifact,
		CodeBuildCloneOutput: jsii.Bool(true),
		ConnectionArn: awsssm.StringParameter_ValueForStringParameter(stack, jsii.String("GITHUB_CONNECTOR_ARN"), nil),
	})

First Deployment

make app
cdk synth
cdk deploy

This will create a self-mutating CodePipeline that continuously deploy to development environment. After this initial deploy, any subsequent deployments will happen automatically - including additional/removal of environments.

More environment can be added by adding following code to ./infrastructure/pipeline.go

// ./infrastructure/pipeline.go
.
.
.
myStage := myapp.NewAppStage(stack, "stage", &myapp.AppStageProps{
    StageProps: awscdk.StageProps{
        Env: &awscdk.Environment{
            Account: "<your-account-number",
            Region: jsii.String("<your-region>"),
        },
    },
})
pipeline.AddApplicationStage(myStage, nil)
// OR if you need manual approval before deployment
// pipeline.AddApplicationStage(myStage, &pipelines.AddStageOptions{
//    ManualApprovals: jsii.Bool(true),
// })

return stack

Then simply do git push

The pipeline will mutate itself to add the new stage, then deploy to it all automatically.

About

Serverless application with CI/CD pipeline written in go using AWS CDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published