AWS re:Invent 2019: [REPEAT 1] Deep dive into AWS Cloud Development Kit (DOP402-R1)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everybody thank you for joining us for a deep dive into the AWS cloud development kit my name is Jason Fulgham I'm the development manager for the AWS cdk hey guys I'm a LOD I'm the principal engineer for the cdk thanks so much for coming it's awesome to see everybody here so there's a bunch of great resources online about some of the basics of the cdk and some introductory material last year a lot and I came to reinvent and during Developer Preview we showed off the typescript experience for the CD came earlier this year after we g8 support for Python we did a fun online tech talk so you can watch those you can learn some of the basics this session it's not going to be the basics though there's gonna be a more advanced session we're gonna get pretty deep or we're gonna cover a lot of deeper topics all of these topics have a lot more meat to them so I hope that you're inspired to go and explore more don't worry if you miss stuff we're gonna leave some little breadcrumbs for you and some point out some resources where you can go and learn more so hope you guys enjoy it plan for the next hour is we're gonna briefly cover some cdk concepts just to make sure we're all on the same page a lot is gonna give us basically a speed run through cdk concepts then we're gonna set up some context for the demo that we're gonna be building we're gonna be revising this fictional walters co company that we've used in previous demos and we're really gonna spend the bulk of our session together live coding in two different parts and we'll wrap up we'll tell you about some more fun stuff going on this week some places you can go to learn more about the cdk this week and online and just how you can keep going deeper into the cdk okay um I'm curious who here heard about the CD Kay okay that's good who used the CD k awesome who contributed code or issues or submitted PRS to the CD K repo yeah thank you yeah super the volume I don't have any control over the volume I can try to like speaker up a little bit yeah I mean it's great like last year I think when we were here there were like five people heard about the cdk in our session so this is really moving and exciting for us as jason said we're gonna do a deep dive or advanced session this this time we've just saw so much really awesome content out there for getting started and so if you're you haven't tried to cdk yet at the end we're gonna provide some links for you to follow so in this part we're just gonna do a quick rundown on like what the cdk is and concept but hopefully most of you know it already so the ctk is a software development framework for defining cloud infrastructure using familiar programming languages and when we use familiar programming language languages we enable us the developers to harness the full power of programming languages and object-oriented design in order to model our infrastructure and define infrastructure logic same way we do for application development and we also allow ourselves to use the same tools techniques and workflows to create an end-to-end process for defining cloud applications both from the infrastructure perspective and the application development and we're seeing a lot of our customers starting to do that and really enjoying this this holistic view we realize that in order to make that work we need to see decay to be available in multiple programming languages and so today's cdk is available in JavaScript typescript Python dotnet and Java and more languages are coming up of course so this is how it works you write your code and one of the supported programming languages cdk applications are structured as a tree of constructs at the root of the tree there's a construct that represents your application and then there are constructs that represent stacks constructs that represent abstract ideas and eventually there are constructs that represent actual cloud resources like s3 buckets or lambda functions and then all of those things form a tree and when you use the cdk CLI to synthesize your application you get CloudFormation templates and other deployment are and then you hand it over to CloudFormation so you get the benefits of using the CloudFormation engine with its transactionality enrollment capabilities and it's declarative approach for desired state configuration while still enjoying the power of general-purpose programming languages and object-oriented and design the cdk contains three main components the core framework the construct library and the cdk CLI the core framework basically has you know the basic building blocks the foundation the app the construct the stack those base classes and the ADA based construct library is a rich class library of constructs that enable you to use AWS through this rich object-oriented API so we have constructs for many AWS services and we're building more and more of them the construct library also includes low-level constructs that represent all of the CloudFormation resource specifications so any CloudFormation resource that's available is available as a strong type class in the construct library but we also have higher level classes that represent all of those resources the CLI is a command-line interface for interacting the cdk applications throughout the development lifecycle it allows you to synthesize apps look at the output of the template diff against the current state deployers your applications etc okay so Jason will walk us through demo scenario and then we're gonna start coding hopefully as soon as possible so just a minute or two on the context of the demo scenario we're gonna be working in today a lot and I are again portraying developers at a fictional company called Walters Cove and a lot and I work on this central infrastructure engineering team so essentially we work with all our application development teams and we help them be successful and use the right patterns and practices for their infrastructure I'm sure that all of you have seen the Ada boost service health dashboard before obviously we do this to give customers and partners transparency into how our systems are operating and we want to do the same thing at Walters Co we have partners and we have customers that rely on our api's so we want to provide this this public facing health dashboard to be transparent about how our systems are operated so on this central infrastructure team Laden I run this service that monitors the health of all the different api's in our company so the application development teams will come to us and they'll provision a resource in this internal system this internal health monitoring system that we run and that system will do health checks on their api's and it will also publish the status out to this public status dashboard so this works well but it does mean that the application teams have this kind of manual step that they have to go through once they had launched a new API or once they expand to a new region they have to remember to come and talk to us and enable their their new region and their new API to be monitored so that's working ok but we'd really like for it to be automated and kind of unified in their provisioning so we're gonna talk in a little bit about how we can use some extensibility features and cloud formation to do that and particularly in the first demo we're gonna dive in and build a construct libraries show off some custom resource providers talk a little bit about how to structure your stacks and also a little bit about some construct design patterns and the second part of the demo we're gonna follow up and keep building on that example and we're gonna show you how we can take that type script construct library and expose it for Java Python and c-sharp developers to use as well we'll talk about some of the tools and techniques we use to build the Atos cdk and the construct library itself how we do multi-language publishing and a little bit about environment to where applications so I will turn things over to a lot and we'll get started with the fun part building some code yeah ok so like Jason said our company has a few service teams they all use cdk to define their infrastructure and what we want to do is we want to enable them to basically use constructs in order to define this resource called health monitor right like it's this internal system that we have that maintains these monitors and shows this status dashboard it's a pretty common scenario I mean many companies have these internal systems and we what we wanted to show in this in this session is how you can integrate these internal systems to the same workflow that you have for for the rest of your architecture and so the first thing we want to do when we design constructs is we call it working backwards it's actually something we use at Amazon a lot for and anywhere in the company and working backwards from the customer experience trying to first thing what the customer how the customer approaches this problem before thinking about the implementation details or the constraints trying to try to think about the mental model of the user and so if I'm a user and I wanted to find a health monitor in my stack then I'd probably do something like this right like I would say new Walters health monitor and then it was specified that app name what region I am at right like these we saw that this health monitor has multiple regions for each app so we should be able to like show that matrix and then the endpoint that I want the health monitor to to monitor and I can create multiple monitors maybe I have multiple endpoints in my service and so this feels like natural and intuitive API for our developers let's start by writing this API and then we see how we actually implemented okay okay so I'm kicking off vs code we have an empty project here it has a cdk app with a test stack this project is actually a library we're not we're not actually vending an app for Apple we want to vend a construct you want event a library for our users and so this app is just defined as an integration test it's kind of like this local thing that I'm using as a developer of this library to test that my my construct works but I'm not actually gonna export it outside of the library okay I'll prove it it it's an empty thing CD case since should so show me an empty template because our stack is empty there's no resources and so first thing I want to do is I want to create my contract I wanted to find it under lead Lib the Lib directory and we'll call it health monitor dot TS and I hope most of you know that construct in the cdk are basically classes that extend the construct based class it's it's a very simple programming model intentionally we wanted to make it really easy for anyone to create their own constructs both for sharing and reuse but also for just organizing your your application into modules into subsystems and so constructs are kind of like classes right so let's define the health monitor construct and extend the construct based class and now let's define the constructor and so constructs all have the same initializer signature they always receive the scope and an identifier which basically creates a namespace and and so constructs have this really powerful capability of creating an isolated namespace within your configuration tree or within your application so we'll see that in a second basically scope is the first parameter ID is the second parameter and in most cases we also have a bunch of properties that we pass into the to the construction so in our case the properties we already showed them earlier it's gonna be a p-- right region and end point pretty straightforward and you know what region is actually something that I can do a little better with because when I define this concept within the context of some stack I actually know the region the stacks gonna go to and so let's make region optional so we can like basically not specified if it if we intend to do two is the same region okay so let's see how I'm gonna use this I hope that that's gonna look like what I expected so I'm gonna do health monitor and let's do AWS home and then app would be AWS home page and endpoint is gonna be with hope that this is gonna be green today just today at least today okay this looks nice this is kind of like what I would expect as a developer if I synthesized this it's still empty right because this construct doesn't have any resources in it it's just this idea now where I write lead I'm expressing in my code and so next thing I want to do is I want to create resources to find resources within this construct and normally I'd use AWS resources like s3 bucket or lambda functions or SNS topics or other constructs that eventually use resources but in our case we don't have an ADA biggest resource and represent our health monitor right like this is kind of like this internal resource that I have in my in my health system and so in order to basically allow cloud formation to provision resources that are not defined in the CloudFormation specification I need to create custom resources and Confirmation has recently launched the confirmation registry which basically allows you to register custom resources formally and basically use them in the template but it's exactly the same thing it's actually exactly the same idea the only difference is that now I'm going to actually define the custom resource within my CD cake application so I don't have to go and publish it anywhere it's just bundled into my application and then when someone uses my library they just get the resource out of the box from that library there are pros and cons to both approaches and you can use both okay so confirmation custom resources I hope that most of you are familiar with them they're actually incredibly powerful you can do awesome things with them cdk has some nice framework for defining for building custom resources and I'm going to use that and I'll show you how how easy it is to create them basically they behave like regular resources they're plugged into the template like any other resource I see this little little yellow thing here and then when CloudFormation sees this resource as part of the provisioning process and makes a decision about what kind of action needs to happen to that resource whether it's creating the resource or updating it or deleting it it'll delegate this activity to the custom resource provider and so that's basically an open-ended thing can do whatever you want there as reaction to that event and in our case what we're gonna do is we're just gonna send some HTTP request to our arrest API as a result of each one of those requests okay let's go go ahead and write that down I'll start by importing a bunch of modules so we're going to import the CloudFormation module we're gonna import the lambda module which is how I'm implementing how I provide my provider implementation and I'm gonna also import the CDKs custom resources module which is the module that contains the high-level abstraction for creating providers um cool so first thing I want to do I'll do it but I'm up okay I'll start with actually defining the resource in my template and then we'll see what the API what the ID tells me to do so I'm gonna do new CF and custom resource we'll call it resource and if I look at the API here I can specify properties provider this is like who's gonna actually implement this removal policy is basically what how confirmation deals with it when when it's removed is it does it leave it as an orphan is it actually deleted and resource type is like the string that basically allows me to differentiate between custom resources within the same template it's actually optional I don't have to specify resource time it's a good practice usually to - if you have multiple types of custom resources it gives you a nice UI cues so let's just do this Walters health monitor and properties I basically want to propagate those properties that I received from the user right so I want app to map to app and endpoint to map to endpoint and region actually needs to either map to region sorry or give me the region from the stack so I'm gonna go up to the stack and get the region and the cdk has this static method called stack of where you can basically find the stack from anywhere you want in the tree so basically give me the stack that this is defined in and so basically stack of this dot region is gonna give me the region and then the last thing I need is the provider and so let's see you can implement a provider by listening to raw CloudFormation events wrists and s or lambda or you can use this CD case custom resource provider framework and as I said we're going to use a provider framework custom resources are not too hard to implement even if you use the raw CloudFormation events there are some pitfalls I don't know if any of you had experience trying to implement custom resources getting your stack stuck for two hours because you forgot to catch some exception and forgot to return the responses and so like the framework makes it really easy to to handle you don't have to care about those things and the framework at the framework also has some pretty nifty feature I'll show you in a second okay so let's just do this provider and so now I'm gonna need to create the provider and I'm gonna use see our provider okay so this is gonna be my provider and if I look at the API here the main method the main API the main property that I need to specify as deon event handler that's a required property it's a lambda function that implements the event handler for my resource I also have the ability to implement another handler called is complete Handler and we're not going to do this this here but the customers our provider framework has this support for asynchronous custom resources and sometimes it's really really useful like in many cases it's not needed but sometimes it takes some time - for resources to actually stabilize or to be eventually consistent and you really don't want a busy wait inside your lambda function it's limited to 15 minutes and costs you money and and so this this method is basically another lambda function that you provide that basically returns true or false if the resource is ready and as long as it's not ready there's a retry policy it will call you back as a stun the policy that you define and only finish the operation when the resource is ready and it's useful for for the use cases that it's needed it's very useful but we're not gonna need this here so I'm just going to basically provide a lambda function here okay new lambda function and Laura and I'm gonna use a handler that I already have here preparin I don't want to spend our time sending HTTP requests that's a different session and so that's a Python handler it has a main method called on event and we're gonna go through this code in a second well this is the point so I'm just gonna basically sorry on then the runtime is Python and the code comes from this asset asset is this local file that's bundled into my project I can publish it as part of my library handler right and I'm also gonna specify the timeout so we're not gonna have any problems with the default time another thing is three seconds or something okay so this is basically all I need right like I now have my provider defined we're gonna look at in a second let me just deploy this and then we're gonna take to check on the provider to forget anything know okay let's get get this going and in the meantime let's take a look take a look at this for a second so the framework calls on event with the event and the context and then we dispatched to one of the three methods create update delete you can do that you don't have to do that depending on your implementation and so now we basically just call into these three methods and it's very straightforward it's basically just mapping the oncreate to post on update to put and on delete to delete which is probably the most expected thing to do and we're actually thinking of providing a custom resource high-level custom resource abstraction that's like automatically mapped to rest api is right like that's that's a common use case but even without that it's pretty easy to implement the only interesting thing that may be worth mentioning here is this concept of a physical resource ID you can see that when I create a monitor I basically get a response that has a monitor ID so it's basically this opaque ID that represents a specific instance of the monitor in the monitoring system and by returning it under the physical resource ID property attribute I basically basically store this information inside the cloud formation database and so next time when CloudFormation updates or delete the same resource it'll give me the ID under the event so I can basically send it over to this REST API and perform the updates most database resources have physical resource IDs right in many cases are there also users can control them like bucket name is a physical resource ID but in many systems they're not in control of the user adjust these opaque tokens that you need to like piggyback okay so this is finished let's see if we have yeah 80s homepage is green this is good USC Swann is basically derived from my environment that's the default environment that I'm set up so this is nice I've got my little resource already but there's a problem here and in order to demonstrate this problem let me let me try and know know if you guys noticed it I'm gonna create another monitor okay let's create a monitor for Amazon home and it's completely legitimate I can create a few of those Amazon and we're past Black Friday so that could be great it's okay and so now created this other monitor and I wanted to show you some some pretty cool tool that we released a couple weeks ago as developer preview it's a very initial version of this tool we have some really fun plans for it it's called a BSC DK Explorer and it's it's part of the vs code extension ADA base vs code extension if I synthesize my my stack and then go to go to this little pain here I can visualize the tree my constructor II I can basically see the the tree of my classroom so I can see the app here and I can see the stack that I have here this is the name of my stack and then you can see that I have AWS home and Amazon Elm and there's another cost structure that was by the system which we should probably like hide somehow but the interesting thing is when I start to dive deeper into this this has become this looks a little weird because now I have basically two resources and each one of those resources has have basically the custom resource defined in it but it also has the entire provider to find inside the resource and the providers are you know they could they could go a little you know they could have some resources that are that support them if use the asynchronous provider you're also going to get a step functions there and so it doesn't really make sense to maintain a single instance of it sorry to maintain a one-to-one relationship between a resource instance as a and a provider I actually want to have a single provider for all those resources there's no need for me to actually maintain one-to-one relationship I need one too many and so what we want to do is we want to get this provider these provider resources and actually define them at the scope of my stack and not the scope of my my resource and cdk makes it really easy to do that so we're gonna implement this singleton pattern right like it's basically I want this thing to only be created once and reused if it's already there right so let's dive into the to this code and I'll show you how how you can do that pretty easily so first thing I want to do I want to create a cost truck that's probably it's true for everything in the cdk health monitor provider sorry and the goal of this construct is to basically sorry package all the resources that are related to the provider into a single entity to a single unit same as before I have a scope and ID and I'm just gonna do a quick quick factor by taking this chunk which contains the lambda function and the provider and the lambda function has that role in it and other things that it's basically a group of resources and just gonna put that here and make that available outside provider C off what's going on my typing today it's it's too excited probe Iver okay good so this done so basically just expose it outside my in my class and now I'm gonna do my provider equals health monitor provider this provider and then here I need to basically use the internal provider because the external thing is just a construct okay let's see what cdk explorer tells us now okay still have two resources here still have two providers now they're nicely packaged together so we can see the we can see this refactor happening in our tree it's not what I want right like I want this provider to define it to be defined at the stack level and so the way I do it is basically let's get a handle to the stack we know how to do that already and I'm just gonna define it here right and now when I'm since I'm defining it to the stack level outside my scope then I need a unique identifier because one of the nice things about cdk constructs is that they give you an isolated namespace so you can just give up give provide those IDs and you control all the IDS in the namespace but what happened what happened if someone would define a construct that the stack scope that has the provider ID we're gonna get a collision and so if you define things outside your scope it's very important to make sure that those things are uniquely identified so they're not colliding with other things especially if you're bending a construct library for other teams right so let's just do something stupid like health monitor Walters whatever something like that and and see what happens let's synthesize this okay well I got an error here there's already a construct with this name right because I've been saturated twice right every time I instantiate my resource it's also instantiates the provider at the stack level so now all I need to do is basically just do this conditional write like reuse the one that's already there if it's there or instantiate a new one and so the pattern is very very straightforward we're just gonna hoist this ID so it's easier to reference because we're gonna need to reference it twice and then I'm gonna do stack dot node dot node in every construct is basically giving you access to the construct tree so it's not about the the resource or the AWS aspect of the construct is about how the construct is operating within this tree there's some really good and useful stuff there if you're interested in exploring more one of the methods there is try find child so it basically tries to find a child based on an ID and that returns null if it doesn't and so all we need to do is basically say try find child ID or new health monitor provider and the the only thing I need to add here is a cat downcast right because tried try find child returns and I construct and I know that this guy is actually a health monitor provider and so this is basically how singleton patterns can be implemented in the cdk last thing I need to do is I'm going to need to change this resource ID and it's a it's a it's a question for the audience at the end come tell us why see if you see if you if you know why okay so this is uh this looks ok it's it's it's it's now synthesizing before I'm deploying this there's just one last thing I want to do because we've been talking and you know we're vending this library for our service teams and we're gonna vend this construct and but this concert has like probably like 10 or 15 resources in it or something like that and it's gonna have more if I'm you know asynchronous or I'm doing something else and our customers are gonna integrate that into their stacks and as you know CloudFormation has a limit of 200 resources in each one of those stacks and so like taking up like 10 or 15 resources of 200 is actually a pretty pretty expensive thing and so what I want to do ideally is I want to take all of this provider stuff and package it as a nested stack nested sack is one resource that represents an entire stack that's deployed by CloudFormation separately and it behaves a regular resource and so let me let me show you how to do that with the CD K that's all so all you have to do is just take a construct turn into nested stack and the CPK is actually doing quite a lot of heavy lifting to make that work seamlessly you can reference things across nested stack boundaries and it'll automatically create parameters and outputs you can create dependencies across nested SEP stack boundaries and it'll automatically find the right place to create this dependency between the two things and so there's a lot of heavy lifting behind this little nested stack thing okay let's just deploy this and do a little look recap and hopefully that will finish before we end the recap okay so we talked about working backwards from the API it was just a little glimpse into the design process that we do for constructs we're seeing more and more that this whole design discipline is something that DevOps engineers and people who've been doing infrastructure you know they're learning how to do that and we're learning how to do that all the time we've got some resources we're actually planning to publish the a Tobias construct library design guidelines document which we use for the a Tobias construct library and so we hope that would be a good reference for you know design principles related to you know designing these class libraries and api's we talked about custom resources and how powerful they are the resource provider framework we talked about conformation registry is an alternative way to publish custom resources but eventually the idea is that you package it as a construct and so a construct is a first-class citizen in the cdk and there's no difference between a construct did you Road or a concert that we rode that came from the construct library and so I think this is one of the most important things to take away right like constructs are all created equal we showed I showed you how to do singleton pattern you can do it at any scope you can do it at the app scope or the environment scope if you want and we briefly showed you how to do nest tax and obviously there are more details to it if you're interested in the documentation and cdk Explorer for vyas code we'd love to know what you guys think about it and what features you'd like to see there we're thinking about you know allowing you to deploy from that tree and DIF from that tree and do some cool stuff that basically not leave your IDE so you can interact with your CDA application very naturally let's see if this is yep okay tada now Amazon's green - great now Jason let's go see how to do some really cool stuff so in the first part of this demo we got this cool typescript cdk construct library we can give that out to all the teams at Walters code that are building their cdk apps and typescript and they can really easily integrate into that health monitoring system but we haven't really solved the problem for our developers that are using Java Python and dotnet so in this next part of the demo we're gonna talk about how we do that for the construct library in the cdk itself how we provide multi languages that's always in sync with the different languages and we're gonna show you how you can do that for your own construct libraries - so a quick history on why where we're at with multi-language support in the cdk and why we think this is so important earlier this year we g8 support for typescript JavaScript and Python and then last week we were super excited to announce GA support for Java and c-sharp as well so as a cdk developer now you have your choice of five languages that you can use in production with that GA stability that backwards compatibility guarantee and we're really excited about that to have those five languages but we're not satisfied we want to keep adding more languages there's a few that we're already playing with we would love to hear from all of you what languages you want to see next for the CDK so please engage us on github we'd love to hear the feedback the reason why we think this is so important to have this multi-language experience is that we see this really strong advantage that developers get when they can take care of their application code and their infrastructure code using the same programming language the same package management tools same development tools they get this nice kind of unified development process where everything just fits together really seamlessly so we're really excited about that and I think that's one of the the things we've been hearing so much customer excitement about so to do that we had to come up with a new way to provide that experience in all these languages we knew that we wanted to provide this multi-language idiomatic experience and we also knew that there was no way we could just brute force it for all these languages and keep them all in sync and keep the features consistent so we invented this new project create this new project called J SII it stands for the JavaScript interoperability interface and essentially what JSI does is we take our typescript code base and we use the JSI tools to produce this metadata that allows us to build these bindings and our target languages on top so when you're using one of these target languages you have the construct library interface exposed and Java or Python or nut you get to interact with that interface well what's happening underneath is you're using the Java code and it's proxying everything over the JSI protocol into a node process that's running all our JavaScript code from our typescript code base so a JSA eye is open source so you can find JSA and github of course you're welcome to use JSA I that we haven't really talked about it a whole lot so we're excited to come and talk about it a little bit more today you're welcome to use it for your construct libraries or even just any other typescript libraries the readme will walk you through how to set up JSA I and some of the constraints you should be aware of and some of the configuration options but let's jump into vs code and let's see if we can turn g-sii on for our typescript library that we just built so first thing we obviously need to get the JSI tools into our workspace so I'm just gonna install these developer dependencies for JSA I and JSI I pack Mac we'll talk about pack Mac a little bit more in a minute that's what actually does the generation and creates the packages for us all right so we've got JSA we've got our tools here let's open up let's open up our package.json and right now we're just building our code with typescript so we want to swap that out and build with JSI instead so a JSA eye is still gonna run the typescript compiler for us is still gonna translate our typescript code and Egeus our into javascript but it's also going to produce a lot of metadata that we'll see in a minute and then we added this new command to run JSI a PAC Mac that we'll get to in a minute so we've got our package set up to run JSA eye but we haven't actually supplied any configuration yet so let's plug this in and take a look so we've added just a little bit more metadata to our package JSON that JSI needs in order to run the most important section is of course the J SII section and this is going to define where we want to output all the code we're generating which languages which target languages want to generate for and then for each of those target languages there are some configuration options how we want to set up the namespaces and stuff like that alright so we've added JSA hi we've set up our build and we've got our configuration in here the last thing I'm gonna do is get rid of our TS config file so when we run JSA I it has some very specific typescript configuration that it relies on so we're just gonna move our TS config file out of the way and we're gonna let JSA I create that TS config file for us so JSI is running its looks like it's updated some of our peer dependencies we've got a new typescript config file but we've got some errors we don't have our JSA metadata yet so let's take a look at what's going on here so in our health monitor class here it looks like JSA is complaining about our health monitor props says the property app and datatype health monitor props must be read-only since the data is passed by value so this is actually a really important point JSA I relies on some constraints on the typescript language and how you write your typescript code so if you want to start using JSA I it's really better to start from the beginning of your project so that you can find these constraints as you hit them quickly it's gonna be easier obviously than trying to take a large typescript code base and removing when you hit those constraints so for example generics is something that we don't support right now and JSI icer if you're using that in your typescript code base we just don't have that feature yet in order to map that into all the target languages so this error specifically is complaining because we've got this interface but our properties in here aren't read-only so that's obviously an easy one for us to fix let's talk for a minute about why we have to do that though so it's important to remember that architecture of JSA I that we talked about a minute ago you've got your target languages sitting on top that you're interfacing directly with and then the communication goes over the JSI protocol into that node process underneath so that no process is really gonna be what's running our infrastructure logic for us and as we pass these health monitor props as we create these in our Java or Python or dotnet code they're gonna be passed by value over that JSA protocol so there's no way for the no process underneath to update the values back in the target language so JSA I wants us to explicitly declare these as read-only so we get that that compiler checking to make sure that we don't ever try to change these values okay so let's see if we can run JSA again and with any luck we should have this new JSA I filed it's produced all this metadata that basically has analyzed our codebase and it's gonna be everything we need to generate the those bindings in the target languages so sure enough here's our JSA I file there's a bunch of information on our dependencies there's a lot of information on the types and our code base and obviously we're gonna use that information to build that bridge in our target languages so now that we've got our JSA metadata we're gonna run our package command so this is invoking JSI pack mac pack mac stands for package maker because that's the output that it's creating it's gonna create these ready to use packages for all the package managers and the languages we're supporting so it looks like our code is generated let's check out this disk directory so this is everything that we've just generated here for Python we've got a wheel file that we could take and deploy to pi PI for our JavaScript code we've got a tgz we can upload to NPM dotnet we've got new get packages of course and then as much as I love Java of course Java always has to be the most verbose we've got about a few dozen maven artifacts ready to use so let's see if we can take some of those maven artifacts now that really build this bridge to our typescript construct library and see if we can use those in a Java app so over in IntelliJ I've got this new Java cdk application that I'm building super simple we've got just one stack in the application right now and inside this stack we've got a single function and a REST API that's running it so what we want to do is add this health monitor into the stack and see if we can get our our Java cdk project to show up on that status dashboard and use that construct library seamlessly from Java so the first thing we need to do is of course pull in that dependency for those maven libraries that we just made and as part of producing those JSI PAC Mac builds those maven artifacts they're already installed locally and our maven local repository so it's very easy for us to just grab these co-taught Walters code and this is our health monitor and the version we declared in our typescript code base was zero point one point zero and we saved that and sure enough under our dependencies may be too small for you all to see but we've got this health monitor jar showing up and we can drill in here and just like we expect to see we've got this health monitor class that maps that same construct we just built in typescript and we've also got this health monitor props interface that declares those three properties we just talked about a minute ago so we've got this code for the this Java bridge into our typescript construct library we've got this loaded into our java application let's see how we in stance this health monitor object and Java so this is our code at Walters health health monitor project here or construct and as we map the typescript code base into these different languages we try to make them fit the style of those languages so the typescript code base the interface is gonna change just a little bit as we map it to different languages so one really common pattern is the the properties that we created to pass into our construct to initialize it as we map those to Python and to nut we have named arguments that we can use for those we don't have that feature in Java so we use a builder pattern instead to get something similar just like we talked about before whenever you create a construct we're gonna specify the enclosing scope for that construct I'm just gonna specify this stack that we're working in so the stack is gonna be the enclosing scope it's gonna it's gonna contain this health monitor construct and we'll give this an ID and at this point we're specifying those construct specific properties so the endpoint that we want to monitor is of course just our API that we just defined on the previous line so we'll grab our URL and this app parameter is the display string that we're gonna see in our our health dashboard so let's call this my new Java cdk service and last but not least of course we have to call build to actually create the object so that's looking pretty good we got this construct used in our Java code this is ready to deploy but before we do I want to talk just for a minute about environment aware applications in the cdk so if we go back and look at our application this is obviously a super simple application we've just got this one stack and this is application is what we would call environment agnostic an environment with the cdk consists of the account and region ID and it tells you where your infrastructure is gonna run so environment equals account plus region right now none of that information is encoded into our cdk application so it's environment agnostic it knows nothing about the environment this is super convenient when you're in development it means you can pick this app up and you can launch in any account in any region but as your application as your system gets more complicated as you have stacks in multiple accounts and multiple regions you're going to want to start encoding that information into your cdk application and that's really easy to do with the environment support in the cdk so the way that you specify the environment information as you create your stacks is by specifying stack properties so we are we're gonna go specify that in a minute but right now we are gonna just specify the environment just pass that in directly if we wanted to specify tag information in our descriptions for our stack and we just go ahead and create the stack properties here but let's just for this demo we'll pass in this cdk environment object again we're in java we're gonna use a builder pattern and we can specify our region or our account we're just gonna go ahead and specify that this stack should always run in US east one so that's the interface that we would like for this new stack and that gives us a really easy way to instantiate this stack in multiple regions so maybe we want a backup stack for redundancy and we'll set this one up to launch in us two so let's go into this constructor and see if we make our code happy again we want to take in this environment parameter and then we specify the environment as part of the stack properties and we always pass the stack properties up to the parent stack and that's how the stack is gonna get that environment information so stack props and we'll just plug in our environment here and that's it it looks like our app code is happy again so let's go ahead and start our deployment we're gonna compile our java code because we made changes of course and then we're gonna run the CD case CLI to deploy this and we specified star you might have seen that on the command line because we now have multiple stacks and we want to deploy all the stacks so let's give this a minute and then when we come back we will look at the status dashboard that we used earlier and we'll see our new Java service is showing up not only for us East one but also in u.s. West too while this is deploying I want to show you one more neat tool that we use to publish our cdk libraries this is another open source project this one is called to live Lib deliver lope stands for deliver libraries and it's a cdk construct library that helps you set up and manage these continuous delivery pipelines using AWS code pipeline and it lets you deliver these code libraries in multiple languages so this is a perfect tool for delivering construct libraries you can run your build with JSI pack Mac and then you can use deliver Lib in your publishing stage to publish to all those different package managers for all the languages that we built so this is another good one to check out this is an experimental project so the api's are likely to change at some point but this is again what we're using for production with a cdk4 the construct library and cdk framework when you stamp out these pipelines the with a to base code pipeline with deliver lib you're gonna get a pipeline that looks like this structure where we've got our source stage pulling data from either github or code commit and then we've got a build stage using code build that's gonna obviously compile our package with our construct libraries we're gonna use JSI pack mac to produce all those different bindings then test stage of course we're gonna run our tests and then the really cool part about delivery is the publishing stage so we have all these pre-configured actions that you can really easily add into your publishing stage to publish to in theone to maven central to github releases pi pi and nougat so that's really really handy if you've ever published to these package managers it's a little bit tedious sometimes to integrate and automate the publishing to package managers deliver lip has that all wrapped up nicely and really easy to use so even if you're not publishing a construct library this can be a really great way to publish a Java library set up a CD pipeline for Java so just to give you a concrete example this is the ATS code pipeline this is our master publishing pipeline or the cdk this publishes the cdk framework database construct library we pulled the source code from github of course we build with code build we're on a ton of tests to make sure that the the releases are ready to go out and then in publishing we're using all of those publishing actions that we just talked about so publishing to github releases and maven central and NPM and pie-pie and nougat so this is again all creator to manage with the deliver Lib project another cool project you can go and try out for your construct libraries or any code libraries and let's check back in on tell a gee there's one more neat trick I want to show you before we go we'll let the suspense build for a minute before we check the status dashboard I wanted to show off this tool for working with JSA I then one of our newest members on the team built and it is called JSA config so this is a nice little visual tool that you can use to help set the age asai configuration settings in your project hmm a lot do you know this one oh I'm in the wrong idea not even close there we go so this should work better NBS code there we go got it so a GFI config has this nice little visual tool that we can use to configure g-sii for our projects you can see the first thing we have to specify is which languages we want to generate for so we can maybe we just want to do Java and.net play with the new GA languages and then for each of the languages we select we're gonna walk through some options for how we want to generate the code or we pull types from and then a lot of specific information for Java and maven and dotnet and Python so a JSI config if you are gonna play with JSA I check out JSA I config little bonus tip for you ok so let's go check our status dashboard on with any luck we should see our new Java service excellent so we've got our new Java C DK service showing up in us east one us too just like we were trying to use and we were able to use that typescript library that we wrote for our health monitor construct use JSA I and really easily use that from our java application a couple of final notes we talked about JSI and JSI PAC Mac a lot really important to understand that those GSI supports a subset a type script so you need to be aware of those constraints as you're playing with JSA I delivery I hope you all go and check that out super cool library great way to set up these continuous delivery pipelines for code libraries and then we kind of scratch the surface a little bit talking about environment to where applications and how you can encode that environment information into your cdk apps as they get more complex okay imma turn things over to a lot to wrap us up thank you okay that was a lot I think but yeah you can always go back and reverse the go back to the to these slides and see what the details are we really wanted to kind of inspire you a little bit too to see where the cdk can go and things that you can do with it there's a lot more and at the end of it there's a little hashtag that we want to wanted you to use a few if you're if you have ideas for demos and things that we want to see from us before we finish we wanted to give a huge shout out to this evolving ecosystem around the cdk project it's it's incredible we were so humbled by the creativity and the amazing work that people are doing both contributing to the cdk directly but also releasing these really creative projects that take the cdk to places that we've never even imagined and so I've been collecting this this list called awesome cdk if you know of other cool projects or you're writing a blog post or giving a talk shoot me an e-mail or a twit or PR to this repo and I'm trying to like catch up it's it's becoming hard actually so help me if you haven't already please take the cdk for a spin cdk workshop comm is a good resource to get started it has a cute tutorial that leads you through your first cdk application supported and all the programming languages that we officially support waxy DK is the CK homepage at Amazon you can find the reference documentation and developer guide there where we know documentation is very important we're really trying we also know that it's not perfect yet so please let us know how we can improve it's also open source you can also contribute to doc documentation but be loud and vocal where where things are not good enough wacks be xvs code is where you can get the vs code extension with the cdk explorer and more than anything we'd love to talk to you we'd love to hear what you guys are building how you're doing where things are working where things are not working please just reach out to us and any channel right like git or github Twitter whatever knock on our doors just come and talk to us we love that that hashtag cdk demo demos is like if you have ideas or things that you want to see live coding in these types of sessions we love the ideas we're kind of running out of ideas at this point every time it's like a big challenge for us so let us know and lastly last year we had two sessions about the city can't reinvent this is a partial list so it's also pretty exciting to see that CDKs is a helping other other you know very very various range of areas and fields in the cloud development space we are also hosting a off reinvent happy hour today with the team we've got our team come in from all over the world to to Vegas and so please come join us at 5 o'clock at Lincoln I think it's not gonna be at this it's like gonna be next door because apparently this bar is under construction or something like that so it's like today we've learned yeah thanks so much for coming we really really appreciate it come talk to us we're gonna hang out here art salad and see you later [Applause]
Info
Channel: AWS Events
Views: 12,909
Rating: undefined out of 5
Keywords: re:Invent 2019, Amazon, AWS re:Invent, DOP402-R1, DevOps, AWS Cloud Development Kit, Not Applicable
Id: 9As_ZIjUGmY
Channel Id: undefined
Length: 57min 5sec (3425 seconds)
Published: Thu Dec 05 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.