Skip to content
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

Deploy to lambdas from cdk #111

Open
wants to merge 84 commits into
base: master
Choose a base branch
from
Open

Conversation

joshprzybyszewski
Copy link
Owner

@joshprzybyszewski joshprzybyszewski commented Nov 15, 2021

What broke / What you're adding

I don't have a way to deploy the app to aws easily. AWS CDK provides a solution to that.

How you did it

@cszczepaniak wrote most of this. I just piggy-packed off what he made.

we're going to stand up a dynamoDB table, that is talked to via a lambda that executes our full server, and then a SPA will talk to it which is served via cloudfront.

How to test it and how to try to break it

  1. Build the lambda binary and the SPA with make lambda spa-bundle in the root directory.
  2. Do a cd infrastructure
  3. Execute make deploy to get the whole stack deployed to us-east-1.
    • You might need to do a make install to ensure that your credentials are set up appropriately.

@@ -36,6 +36,7 @@ func NewFactory(ctx context.Context, config Config) (persistence.DBFactory, erro
}

if config.RunCreateStmts {
log.Println("Run Create Stmts...")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC I added these when I had no clue what I was doing and trying to get connected to RDS. Maybe we can clean these up?

server/setup.go Outdated
ctx, fn := context.WithTimeout(context.Background(), 4*time.Minute)
defer fn()

log.Printf("Fetching DB (createTables: %v)\n", *createTables)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC I added these when I had no clue what I was doing and trying to get connected to RDS. Maybe we can clean these up?

// TODO somewhere between the

// TODO perhaps use https://github.com/aws-samples/aws-cdk-examples/blob/901ae3e11704fc378ade673f76f0eeae860a5daf/typescript/static-site/static-site.ts#L113-L127
// as an example for deploying CDN-like
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a CDK plugin (library? idk what they're called) that makes deploying the frontend to S3+CloudFront like 3 lines. We should use that.

https://github.com/cszczepaniak/oh-hell-scorecard/blob/7ea3b0ff4ce229d035bd5b100560399ac56be48c/infrastructure/lib/infrastructure-stack.ts#L8-L12

// as an example for deploying CDN-like

// TODO re-architect the frontend so that the "backend" calls go to a different sub-domain to hit
// the lambda, and all of hobbycribbage.com/ just goes to a CDN to get the page. It's a SPA, so
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above link for pointing our domain at our CDN. As for the frontend changes, they'll be ezpz as well. Should just be swapping out or adding a baseURL.

… into deployToLambdasFromCDK

 Conflicts:
	.github/workflows/go_tests.yaml
	client/src/app/containers/Game/useGame.ts
	client/src/app/containers/Home/useActiveGames.ts
	client/src/auth/useAuth.ts
	docker-compose.yml
	go.mod
	go.sum
	server/persistence/dynamo/utils.go
	server/persistence/dynamo/utils_test.go
	server/server.go
@joshprzybyszewski joshprzybyszewski marked this pull request as ready for review November 29, 2021 03:26
name: Deploy to AWS

on:
pull_request: # for now, trigger this on PR so I can test it before merging
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:badpokerface:

shell: bash

jobs:
dockerimage:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this? We're not using a docker image, right?

proxy: true,
deployOptions: {
stageName: 'urlprefix',
// tracingEnabled: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌵 Do we need this still?

handler: props.lambda,
proxy: true,
deployOptions: {
stageName: 'urlprefix',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 'urlprefix' a special stage name, or will this make our URL http://something/urlprefix/?

const subdomain = 'lambda.hobbycribbage.com';
restApi.addDomainName("domain_name", {
domainName: subdomain,
// securityPolicy: apigw.SecurityPolicy.TLS_1_2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌵 Do we still need this?

new ARecord(this, `${id}-r53-a-record`, {
zone: zone,
recordName: subdomain,
comment: 'A comment on the ARecord',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:badpokerface:

});

// https://github.com/cszczepaniak/oh-hell-scorecard/blob/7ea3b0ff4ce229d035bd5b100560399ac56be48c/infrastructure/lib/infrastructure-stack.ts#L8-L12
const zipFileName = 'spa-bundle';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I missed this in the previous PR, but just like our lambda zip file, we may want to put the git commit hash in the name here if we want to be able to easily deploy different commits (the commit could be an input to the GitHub action if we add a manual deploy option, even)

aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Install CDK and Stack Dependencies
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Maybe in a future improvement, we could split our frontend/backend CDK stacks and conditionally deploy them in our github actions based on the files touched in a given PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants