<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Miguel Ruiz on Medium]]></title>
        <description><![CDATA[Stories by Miguel Ruiz on Medium]]></description>
        <link>https://medium.com/@miruiz?source=rss-3a53235607d4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*h8hghvyC34yN_htxpJzplw.jpeg</url>
            <title>Stories by Miguel Ruiz on Medium</title>
            <link>https://medium.com/@miruiz?source=rss-3a53235607d4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 15:33:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@miruiz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Case Study in Modular Design]]></title>
            <link>https://medium.com/expedia-group-tech/case-study-in-modular-design-e0aacac872d3?source=rss-3a53235607d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0aacac872d3</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Miguel Ruiz]]></dc:creator>
            <pubDate>Tue, 11 Sep 2018 17:11:29 GMT</pubDate>
            <atom:updated>2018-09-13T16:46:27.422Z</atom:updated>
            <content:encoded><![CDATA[<p>We have covered quite a bit so far on how our application is architected. If you missed out on following it, check out our other blog post in this series:</p><ul><li><a href="https://medium.com/expedia-engineering/using-aws-managed-services-in-an-enterprise-environment-1bceb1841cde">Using AWS Managed Services in an Enterprise Environment</a></li><li><a href="https://medium.com/expedia-engineering/designing-apis-to-be-modular-deployable-and-secure-76960c39d610">Designing APIs to be Modular, Deployable, and Secure</a></li><li><a href="https://medium.com/expedia-engineering/aws-cognito-aws-lambda-serverless-framework-react-with-redux-92cdfec83df2">AWS Cognito + AWS Lambda + Serverless Framework + React with Redux</a></li><li><a href="https://medium.com/expedia-engineering/using-api-gateway-for-authorization-and-authentication-894a403d8614">Using API Gateway for Authorization and Authentication</a></li></ul><p>At the start of any software development project, it’s impossible to predict how it will grow. A sudden jump in the scale of your user base, a change in requirements, or even a new feature release from your cloud provider can have a huge impact.</p><p>Change will happen. That’s just a reality. The environment around your application might evolve in a way that invalidates a decision you made months earlier.</p><p>In this blog post, we’ll look at what it took to keep our application adaptable.</p><h3>Form Field Configuration: ricocheting between an API and a module</h3><p>If you remember from the <a href="https://medium.com/@miruiz/using-aws-managed-services-in-an-enterprise-environment-1bceb1841cde">first post</a>, our application collects data from new employees around the world and what data was required was different from country to country.</p><p>So, how can we control that? It’s hard to know what the right decision should be. But we had one guiding principle: adding field requirements for new countries needed to be as easy as possible.</p><p>Easy for whom? An employee who is not strong technically? A junior developer? An outsourcing team? We didn’t know at the time, but sticking to a philosophy that adding new countries needs to be easy, whatever that meant, ultimately helped us stay flexible.</p><h3>v1 Configuration File</h3><p>In the beginning, it was just a JSON file containing all the data necessary to render fields on the form. You had a field name, title, and field type. What more do you need?</p><h4>JSON is not a programming language</h4><p>A lot, it turns out. Is the field required? How about a regex to validate data? Does that regex apply worldwide? The system of record for this data has a complicated interface that changes without warning, so the complexity of parsing out data was pushed into the config file. Sometimes the way you get data from the system of record is different from the way you save it back.</p><p>It didn’t take long to realize this was not a workable solution…</p><h3>v2 Node Module</h3><p>Having outgrown the might of JSON, we started moving towards turning this into a node module. We built a directory structure that looked something like this:</p><pre>├── /src<br>│   ├── /models<br>│   └── /data<br>│   └── index.js</pre><p>What was once the JSON configuration file was moved into the /data directory. Complex functionality, like the aforementioned data parsing, was moved to a /models directory.</p><p>This worked great! It was easy for a developer to add new fields, and there was a place for additional code to live for anything more complicated.</p><h4>Uh oh…</h4><p>We got a new requirement: there needs to be a UI for users to add or remove fields, and launch new countries. Our “flat file” database isn’t going to work anymore. This, coupled with other requirements, drove the decision to turn this application into an API.</p><h3>v3 RESTful API</h3><p>This turned out to be easy. We added <a href="https://github.com/koajs/koa">Koa</a>, and a /routes directory to expose the functionality that was written in /models. So now our directory structure looks like this:</p><pre>├── /src<br>│   ├── /routes<br>│   ├── /models<br>│   └── /data<br>│   └── index.js</pre><p>Once that was done, we moved the flat files into DynamoDB, deployed the whole thing into our ECS cluster, and called it good. It only took a day or so.</p><h4>Man, you talk a lot</h4><p>This had a devastating effect on performance. We had two APIs: this one and one that actually communicated with our people management software. This made them incredibly chatty and slow as a result.</p><blockquote><strong><em>Remind me again why you split this responsibility out. </em></strong><em>We knew we needed to make launching new countries and changing fields around easy. And while we weren’t sure who would take that on, our product owners were adamant it would </em>not<em> be the development team. This needed to be something encapsulated that could be handed off to someone else. Whoever that was might not have the legal right to have access to our people management software API. This drove the decision split this into its own project.</em></blockquote><p>It was also becoming clear that having a UI that an unskilled person could use to manipulate the form was not realistic. Mostly because our people management software’s API was so inconsistent and complex, but also because the onboarding form itself was getting more and more complex. Having fields that are only required depending on how other fields are filled out, dynamically showing sections of the form…this would only be possible by inventing a simple programming language for people to use in our UI, which is a step down the road of <a href="https://thedailywtf.com/articles/The_Inner-Platform_Effect">The Inner Platform Effect</a>.</p><p>Never mind the fact there were better incremental steps that could’ve been taken, such as keeping it as a node module, but putting the data in DynamoDB, with a UI in front of the database. Hind sight is 20/20.</p><h3>v4 Back to a Node Module</h3><p>We started the journey back to an node module by ripping out <a href="https://github.com/koajs/koa">Koa</a>, the /routes directory, and the data in DynamoDB. Now that we’re free from the constraint of building a UI, we could start to organize the project in a way that makes sense for a developer. And chances are, it’ll stay that way. The power user UI was cut by our product team.</p><h3>Lessons learned</h3><p>Focusing on the right priorities helped us to keep our application flexible so we were free to experiment. Ultimately, we landed on a paradigm that works best for us.</p><p>It’s easy for a technical lead to myopically focus on architectural patterns when what matters is the software is easily understood, maintained, and performant. Hypothetically, if we had decided in the beginning that because we’re aiming for a microservices environment everything needs to be a RESTful API, it would have been easy to create something architecturally pure, but severely broken in more significant ways.</p><p>Instead, we kept in mind the goal of keeping this functionality as easy to change as possible, whatever that meant.</p><p>By keeping our application code properly encapsulated (primarily through dependency injection and relying on AWS Managed Services), we were able to try new things. Each of our services are small enough to rebuild in under one sprint.</p><p>It’s impossible to predict how your application will need to change in the future, but by planning for change and making your code reusable, you’ll be able to avoid the technical debt plaguing teams as software projects drag on.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0aacac872d3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expedia-group-tech/case-study-in-modular-design-e0aacac872d3">Case Study in Modular Design</a> was originally published in <a href="https://medium.com/expedia-group-tech">Expedia Group Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using API Gateway for Authorization and Authentication]]></title>
            <link>https://medium.com/expedia-group-tech/using-api-gateway-for-authorization-and-authentication-894a403d8614?source=rss-3a53235607d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/894a403d8614</guid>
            <category><![CDATA[api-security]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[authentication]]></category>
            <dc:creator><![CDATA[Miguel Ruiz]]></dc:creator>
            <pubDate>Mon, 10 Sep 2018 17:33:52 GMT</pubDate>
            <atom:updated>2018-09-13T16:45:24.665Z</atom:updated>
            <content:encoded><![CDATA[<p>We have covered quite a bit so far on how our application is architected. If you missed out on following it, check out our other blog post in this series:</p><ul><li><a href="https://medium.com/expedia-engineering/using-aws-managed-services-in-an-enterprise-environment-1bceb1841cde">Using AWS Managed Services in an Enterprise Environment</a></li><li><a href="https://medium.com/expedia-engineering/designing-apis-to-be-modular-deployable-and-secure-76960c39d610">Designing APIs to be Modular, Deployable, and Secure</a></li><li><a href="https://medium.com/expedia-engineering/aws-cognito-aws-lambda-serverless-framework-react-with-redux-92cdfec83df2">AWS Cognito + AWS Lambda + Serverless Framework + React with Redux</a></li><li><a href="https://medium.com/expedia-engineering/case-study-in-modular-design-e0aacac872d3">Case Study in Modular Design</a></li></ul><p>You have many different options when it comes to implementing authorization and authentication. We had no particular requirements other than there needed to be some, and that it couldn’t be “static” (e.g. a hardcoded username and password passed along with everything request).</p><p>We looked at different options before settling on API Gateway. Being a NodeJS app, <a href="https://github.com/jaredhanson/passport">Passport</a> was the most popular choice. I had also built my own authentication method for another project (<strong>side note: </strong>never do this). Ultimately, though, we wanted something we didn’t have to maintain the health of.</p><h3>API Gateway to the rescue</h3><p>API Gateway seemed like a perfect fit except for one thing: at the time, you couldn’t put API Gateway in front of resources inside a VPC.</p><p>After some discussion, we decided to punt. Our application was only running in a lab environment, and it would be some time before it was exposed to the public internet. In the mean time, we decided that whatever we used for authorization and authentication, it would have to be implemented in a way similar to API Gateway; something would sit in front of our application to handle this responsibility. This functionality would not be embedded in our application code. If we chose something that worked in a similar way, then it would be easier to make the switch if API Gateway ever became viable.</p><p>So we waited and researched other options. We didn’t know if AWS would ever support such a scenario. All we could find were some random forum posts from the official forum saying they were looking into it.</p><h3>I mean…NLBs to the rescue!</h3><p>In late 2017, we were thrown a lifeline. AWS released their <a href="https://aws.amazon.com/blogs/aws/new-network-load-balancer-effortless-scaling-to-millions-of-requests-per-second/">Network Load Balancer </a>which finally gave us the ability to expose resources inside our VPC out through API Gateway.</p><blockquote><strong><em>I don’t want to use an NLB </em></strong><em>Too bad. At time of writing, if you want to use API Gateway and VPCs, it has to be behind an NLB.</em></blockquote><h3>How to make this happen</h3><p>We’ll be creating cloud formation templates for the following…</p><p>1. Network Load Balancer<br>2. Network Load Balancer Targets<br>3. API Gateway<br>4. API Gateway Deployment</p><blockquote><strong><em>Can’t I use the console? </em></strong><em>You’re welcome to figure that out. We deploy our application using CFTs. There’s no benefit doing this through the console unless you intend to manually configure all your resources, across all your environments. But don’t do that. Using CFTs will make deploying your application much easier.</em></blockquote><h4>Network Load Balancer and its Targets</h4><p>The CFT for the load balancer is pretty self explanatory. It looks like this:</p><pre>Description: Load Balancer for ApplicationAPI<br>Parameters:<br>  Stage:<br>    Type: String<br>    Description: Deployment stage for this instance of ApplicationAPI<br>  Subnets:<br>    Type: List&lt;AWS::EC2::Subnet::Id&gt;<br>    Description: List of Subnets, need to be across 2 availability zones<br>Resources:<br>    ApplicationAPILoadBalancer:<br>        Type: &quot;AWS::ElasticLoadBalancingV2::LoadBalancer&quot;<br>        Properties:<br>          Name:<br>            !Join<br>                - &#39;&#39;<br>                - - &#39;applicationapi-&#39;<br>                  - !Ref Stage<br>                  - &#39;-lb&#39;<br>          Scheme: internal<br>          Subnets: !Ref Subnets<br>          Type: network<br>          IpAddressType: ipv4</pre><p>It takes only a Stage name, which can be anything that makes sense to you. Also to be supplied is a list of subnets you expect your ECS service to be running in.</p><blockquote><strong><em>Explanation of Stage name </em></strong><em>Stage is a variable we use across all our CFTs, so you’ll see it a lot. We use it to differentiate between what are traditionally called “environments”. So we have a “dev” stage, a “staging” stage, and others as needed.</em></blockquote><p>Next we need to set up the targets. The CFT looks something like this:</p><pre>Description: Load Balancer for ApplicationAPI<br>Parameters:<br>  LoadBalancerArn:<br>    Type: String<br>    Description: ARN of a load balancer instance<br>  Stage:<br>    Type: String<br>    Description: Deployment stage for this instance of ApplicationAPI<br>  Vpc:<br>    Type: AWS::EC2::VPC::Id<br>    Description: VPC ID<br>Resources:<br>    ApplicationAPITargetGroup:<br>        Type: &quot;AWS::ElasticLoadBalancingV2::TargetGroup&quot;<br>        Properties:<br>          Name:<br>            !Join<br>                - &#39;&#39;<br>                - - &#39;applicationapi-&#39;<br>                  - !Ref Stage<br>                  - &#39;-targetgroup&#39;<br>          Port: 80<br>          Protocol: TCP<br>          TargetType: ip<br>          VpcId: !Ref Vpc<br>    ApplicationAPIListener:<br>        Type: &quot;AWS::ElasticLoadBalancingV2::Listener&quot;<br>        Properties:<br>          DefaultActions:<br>            - Type: forward<br>              TargetGroupArn:<br>                    Ref: ApplicationAPITargetGroup<br>          LoadBalancerArn:<br>              Ref: LoadBalancerArn<br>          Port: 80<br>          Protocol: TCP</pre><p>The TargetType: ip attribute is critical to getting this working with Fargate. The NLB’s target group needs to know that it’s balancing across IP Addresses, rather than instance ids. The target will be associated with the ECS service in another CFT, and it’s from that connection that Fargate will be able to associate the IP Address with balancer target groups.</p><p>Note there’s also a AWS::ElasticLoadBalancingV2::Listener, which creates a listener for our NLB, checking for connection requests and forwarding them to the target groups.</p><h3>API Gateway</h3><p>This API Gateway sits in front of an application running in Fargate. That application has routes exposed and returns valid HTTP status codes depending on the situation. With that in place, the API Gateway can simply allow requests and responses pass back and forth.</p><blockquote><strong><em>A quick note about our application </em></strong><em>It’s a NodeJS app using </em><a href="https://github.com/koajs/koa"><em>Koa</em></a><em> as a web server. It has routes defined by means of the </em><a href="https://github.com/alexmingoia/koa-router"><em>koa-router</em></a><em> module and is strict about ensuring that all output is HTTP friendly. This allows API Gateway to act as a simple proxy. We could’ve pushed some of that responsibility on to API Gateway, but it didn’t make sense given some of our other application requirements.</em></blockquote><p>It’s possible to define a bunch of AWS::ApiGateway::Method in the CFT for your API Gateway to define the routes, but there are some things you can’t take advantage of if you go that way, such as setting a VPC Link.</p><p>So, you’ll need to define a AWS::ApiGateway::RestAPI with a Body containing the definition for your routes. The easiest way to bootstrap this CFT is to manually build an API Gateway in the console, deploy it, and then use the export option. To do that, select <strong>Stages &gt; [stage name] &gt; Export &gt; Export as Swagger + API Gateway Extensions</strong>. Copy/Paste the output as the Body for your AWS::ApiGateway::RestAPI, and you should be on your way.</p><blockquote><strong><em>Wait, why am I building this in the console first? </em></strong><em>Some of the options in the console don’t have clear cut analogs in cloud formation. CORS is the perfect example. It’s a single button in the console, but there’s no </em><em>enable-cors flag in cloud formation. You have to add specific header definitions you’ll see below. We simply found it easier to start with the console first.</em></blockquote><p>As a last step, delete the API Gateway you just created. You’ll deploy it using a CFT next time.</p><p>After bootstrapping the template and continuing to develop it, it looks something like this:</p><pre>Description: APIGateway in front of ApplicationAPI<br>Parameters:<br>  NlbArn:<br>    Type: String<br>    Description: ARN of the NLB for ApplicationAPI<br>  NlbDns:<br>    Type: String<br>    Description: DNS name of the NLB for ApplicationAPI<br>  Stage:<br>    Type: String<br>    Description: Deployment Stage<br>Resources:<br>    ApplicationAPIVpcLink:<br>        Type: &quot;AWS::ApiGateway::VpcLink&quot;<br>        Properties:<br>          Description: VPC Link to ApplicationAPI NLB<br>          Name: !Sub applicationapi-${Stage}-vpclink<br>          TargetArns:<br>            - !Ref NlbArn<br>    ApplicationApi:<br>        Type: &quot;AWS::ApiGateway::RestApi&quot;<br>        Properties:<br>            Description: API for accessing applicationAPI<br>            EndpointConfiguration:<br>                Types:<br>                    - REGIONAL<br>            Name: !Sub applicationapi-${Stage}-api<br>            Body:<br>                swagger: &quot;2.0&quot;<br>                schemes:<br>                - &quot;https&quot;<br>                paths:<br>                  /_application:<br>                    options:<br>                      consumes:<br>                      - &quot;application/json&quot;<br>                      produces:<br>                      - &quot;application/json&quot;<br>                      responses:<br>                        &quot;200&quot;:<br>                          description: &quot;200 response&quot;<br>                          schema:<br>                            $ref: &quot;#/definitions/Empty&quot;<br>                          headers:<br>                            Access-Control-Allow-Origin:<br>                              type: &quot;string&quot;<br>                            Access-Control-Allow-Methods:<br>                              type: &quot;string&quot;<br>                            Access-Control-Allow-Headers:<br>                              type: &quot;string&quot;<br>                      x-amazon-apigateway-integration:<br>                        responses:<br>                          default:<br>                            statusCode: &quot;200&quot;<br>                            responseParameters:<br>                              method.response.header.Access-Control-Allow-Methods: &quot;&#39;DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT&#39;&quot;<br>                              method.response.header.Access-Control-Allow-Headers: &quot;&#39;Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token&#39;&quot;<br>                              method.response.header.Access-Control-Allow-Origin: &quot;&#39;*&#39;&quot;<br>                        requestTemplates:<br>                          application/json: &quot;{\&quot;statusCode\&quot;: 200}&quot;<br>                        passthroughBehavior: &quot;when_no_match&quot;<br>                        type: &quot;mock&quot;<br>                  /_application/{token}:<br>                    get:<br>                      produces:<br>                      - &quot;application/json&quot;<br>                      parameters:<br>                      - name: &quot;token&quot;<br>                        in: &quot;path&quot;<br>                        required: true<br>                        type: &quot;string&quot;<br>                      security:<br>                      - sigv4: []<br>                      x-amazon-apigateway-integration:<br>                        uri:<br>                            Fn::Sub: <a href="http://${nlbdns}/_application/%7Btoken%7D">http://${NlbDns}/_application/{token}</a><br>                        requestParameters:<br>                          integration.request.path.token: &quot;method.request.path.token&quot;<br>                        passthroughBehavior: &quot;when_no_match&quot;<br>                        connectionType: &quot;VPC_LINK&quot;<br>                        connectionId:<br>                            Ref: ApplicationAPIVpcLink<br>                        httpMethod: &quot;GET&quot;<br>                        type: &quot;http_proxy&quot;<br>                    put:<br>                      produces:<br>                      - &quot;application/json&quot;<br>                      parameters:<br>                      - name: &quot;token&quot;<br>                        in: &quot;path&quot;<br>                        required: true<br>                        type: &quot;string&quot;<br>                      security:<br>                      - sigv4: []<br>                      x-amazon-apigateway-integration:<br>                        uri:<br>                            Fn::Sub: <a href="http://${nlbdns}/_application/%7Btoken%7D">http://${NlbDns}/_application/{token}</a><br>                        requestParameters:<br>                          integration.request.path.token: &quot;method.request.path.token&quot;<br>                        passthroughBehavior: &quot;when_no_match&quot;<br>                        connectionType: &quot;VPC_LINK&quot;<br>                        connectionId:<br>                            Ref: ApplicationAPIVpcLink<br>                        httpMethod: &quot;PUT&quot;<br>                        type: &quot;http_proxy&quot;<br>                    options:<br>                      consumes:<br>                      - &quot;application/json&quot;<br>                      produces:<br>                      - &quot;application/json&quot;<br>                      responses:<br>                        &quot;200&quot;:<br>                          description: &quot;200 response&quot;<br>                          schema:<br>                            $ref: &quot;#/definitions/Empty&quot;<br>                          headers:<br>                            Access-Control-Allow-Origin:<br>                              type: &quot;string&quot;<br>                            Access-Control-Allow-Methods:<br>                              type: &quot;string&quot;<br>                            Access-Control-Allow-Headers:<br>                              type: &quot;string&quot;<br>                      x-amazon-apigateway-integration:<br>                        responses:<br>                          default:<br>                            statusCode: &quot;200&quot;<br>                            responseParameters:<br>                              method.response.header.Access-Control-Allow-Methods: &quot;&#39;DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT&#39;&quot;<br>                              method.response.header.Access-Control-Allow-Headers: &quot;&#39;Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token&#39;&quot;<br>                              method.response.header.Access-Control-Allow-Origin: &quot;&#39;*&#39;&quot;<br>                        requestTemplates:<br>                          application/json: &quot;{\&quot;statusCode\&quot;: 200}&quot;<br>                        passthroughBehavior: &quot;when_no_match&quot;<br>                        type: &quot;mock&quot;<br>                  /health:<br>                    get:<br>                      produces:<br>                      - &quot;application/json&quot;<br>                      security:<br>                      - sigv4: []<br>                      x-amazon-apigateway-integration:<br>                        uri:<br>                            Fn::Sub: <a href="http://${nlbdns}/health">http://${NlbDns}/health</a><br>                        passthroughBehavior: &quot;when_no_match&quot;<br>                        connectionType: &quot;VPC_LINK&quot;<br>                        connectionId:<br>                            Ref: ApplicationAPIVpcLink<br>                        httpMethod: &quot;GET&quot;<br>                        type: &quot;http_proxy&quot;<br>                    options:<br>                      consumes:<br>                      - &quot;application/json&quot;<br>                      produces:<br>                      - &quot;application/json&quot;<br>                      responses:<br>                        &quot;200&quot;:<br>                          description: &quot;200 response&quot;<br>                          schema:<br>                            $ref: &quot;#/definitions/Empty&quot;<br>                          headers:<br>                            Access-Control-Allow-Origin:<br>                              type: &quot;string&quot;<br>                            Access-Control-Allow-Methods:<br>                              type: &quot;string&quot;<br>                            Access-Control-Allow-Headers:<br>                              type: &quot;string&quot;<br>                      x-amazon-apigateway-integration:<br>                        responses:<br>                          default:<br>                            statusCode: &quot;200&quot;<br>                            responseParameters:<br>                              method.response.header.Access-Control-Allow-Methods: &quot;&#39;DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT&#39;&quot;<br>                              method.response.header.Access-Control-Allow-Headers: &quot;&#39;Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token&#39;&quot;<br>                              method.response.header.Access-Control-Allow-Origin: &quot;&#39;*&#39;&quot;<br>                        requestTemplates:<br>                          application/json: &quot;{\&quot;statusCode\&quot;: 200}&quot;<br>                        passthroughBehavior: &quot;when_no_match&quot;<br>                        type: &quot;mock&quot;<br>                securityDefinitions:<br>                  sigv4:<br>                    type: &quot;apiKey&quot;<br>                    name: &quot;Authorization&quot;<br>                    in: &quot;header&quot;<br>                    x-amazon-apigateway-authtype: &quot;awsSigv4&quot;<br>                definitions:<br>                  Empty:<br>                    type: &quot;object&quot;<br>                    title: &quot;Empty Schema&quot;<br>                x-amazon-apigateway-binary-media-types:<br>                  - &quot;multipart/form-data&quot;<br>    ApplicationAPI4XXGatewayResponses:<br>        Type: AWS::ApiGateway::GatewayResponse<br>        Properties:<br>          ResponseParameters:<br>            gatewayresponse.header.Access-Control-Allow-Origin: &quot;&#39;*&#39;&quot;<br>            gatewayresponse.header.Access-Control-Allow-Headers: &quot;&#39;*&#39;&quot;<br>          ResponseType: DEFAULT_4XX<br>          RestApiId: !Ref ApplicationApi<br>    ApplicationAPI5XXGatewayResponses:<br>        Type: AWS::ApiGateway::GatewayResponse<br>        Properties:<br>          ResponseParameters:<br>            gatewayresponse.header.Access-Control-Allow-Origin: &quot;&#39;*&#39;&quot;<br>            gatewayresponse.header.Access-Control-Allow-Headers: &quot;&#39;*&#39;&quot;<br>          ResponseType: DEFAULT_5XX<br>          RestApiId: !Ref ApplicationApi</pre><pre>Outputs:<br>  ApplicationApiId:<br>    Description: API Id<br>    Value: !Ref ApplicationApi</pre><p>The first thing defined is a VPC Link. This is what will allow your API Gateway to talk to the application running in your VPC. It’s pretty straightforward, the only thing it needs to know about is the NLB Arn.</p><p>Next is our AWS::ApiGateway::RestApi. All our paths are defined, along with each supported verb, and what content types to expect.</p><blockquote><strong><em>What’s up with the underscore? </em></strong><em>We do our best to follow RESTful principles, but we needed a way to communicate that some routes are </em><em>helper routes that may not follow be RESTful, perhaps because it’s using an unusual HTTP verb. We adopted a leading underscore to highlight this.</em></blockquote><p>A few things to note:</p><p>1. Setting security to sigv4 (also notice the securityDefinitions definitions block at the end) is what allows you to secure your routes with IAM permissions.<br>2. The definition for OPTIONS should NOT have any security around it. Browsers hit it at their discretion, and there’s no way to add authorization headers to that request. It must be left open.<br>3. This block allows for multipart form posts. This was something API Gateway didn’t support until recently and is another example of a critical feature you might not realize is available.</p><pre>x-amazon-apigateway-binary-media-types:<br>  - &quot;multipart/form-data&quot;</pre><p>4. Finally, the blocks for 4XX and 5XX errors allow errors thrown in the app to pass all the way to the client. Each error thrown in the application is HTTP friendly. (Using the <a href="https://github.com/hapijs/boom">Boom </a>module).</p><h4>API Gateway Deployment</h4><p>We have a separate CFT for the API Gateway deployment. It’s so straightforward it isn’t worth discussing. Here’s the template in case you’re curious</p><pre>Description: ApiGateway API Deployment for ApplicationAPI<br>Parameters:<br>  ApiId:<br>    Type: String<br>    Description: ApiId for applicationapi-api<br>  Stage:<br>    Type: String<br>    Description: Deployment stage<br>Resources:<br>    ApplicationAPIDeployment:<br>        Type: &quot;AWS::ApiGateway::Deployment&quot;<br>        Properties:<br>          Description: !Sub Deployment for applicationapi-api (v0.0.1)<br>          RestApiId: !Ref ApiId<br>          StageName: !Ref Stage</pre><h4>IAM permissions</h4><p>Just a quick word about API permissions. You’ll want to apply the execute-api:Invoke permission to anything needing access to this API. It’ll look something like this:</p><pre>{<br>    &quot;Action&quot;: [<br>        &quot;execute-api:Invoke&quot;<br>    ],<br>    &quot;Resource&quot;: &quot;arn:aws:execute-api:*:*:apiId/*&quot;,<br>    &quot;Effect&quot;: &quot;Allow&quot;<br>}</pre><p>apiId is where the actual id for your API is supposed to go. You have wide power to lockdown your APIs. The policy aboves grants unrestricted access to the API, but you can lock things down by resource and verb.</p><h3>Conclusion</h3><p>Obviously, a few pieces are missing. You’ll need an application the NLB is in front of, and you’ll still need to define all your IAM permissions. But those are elements unique to your application. Hopefully, you can take what you’ve learned here and apply it to your app.</p><p>Finally, if there’s anything unclear, please let me know in the comments below. We understand how frustrating it can be to read blog posts missing the critical piece of information you are looking for, and we want to be comprehensive.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=894a403d8614" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expedia-group-tech/using-api-gateway-for-authorization-and-authentication-894a403d8614">Using API Gateway for Authorization and Authentication</a> was originally published in <a href="https://medium.com/expedia-group-tech">Expedia Group Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using AWS Managed Services in an Enterprise Environment]]></title>
            <link>https://medium.com/expedia-group-tech/using-aws-managed-services-in-an-enterprise-environment-1bceb1841cde?source=rss-3a53235607d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bceb1841cde</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Miguel Ruiz]]></dc:creator>
            <pubDate>Tue, 04 Sep 2018 15:58:31 GMT</pubDate>
            <atom:updated>2018-09-13T16:47:28.811Z</atom:updated>
            <content:encoded><![CDATA[<p>AWS offers a wide variety of services to make modern application development easy. No matter what type of application you’re building, you can focus on your application code by mapping your architecture to these managed services.</p><p>You <em>should</em> be able to…but working in an enterprise environment where you need to comply with requirements from an internal security team may add nuance to your application that makes using managed services much much harder. Documentation often only covers the happiest of happy path scenarios, and some services may have subtle feature gaps that can impact your architecture.</p><p>This can drive you towards using “primitive” AWS services: running your application on an EC2 instance behind an ALB. This is much more expensive, less secure, and harder to maintain. The responsibility of keeping your servers patched, and your application healthy falls on you.</p><p>Over the next four blog posts, we’ll be covering how we at Expedia Group made AWS Managed Services work for us, while still remaining in compliant with both privacy laws and and internal security policies.</p><p>So first, what kind of application is this?</p><h3>Employee Onboarding</h3><p>Human Resources is not a place we typically think of when it comes to cutting edge software development. But at the Expedia Group, technology and cloud adoption is everywhere, including our Human Resources department. We had a very real software need: securely collect data about newly hired employees around the world. Expedia Group employs people from over 60 countries, and only a handful of people are staffed to help new hires through on onboarding process.</p><p>Each country has different requirements about what data we need to have about our employees. Mandatory data in some countries, might be illegal to ask for in others. And while our people management software can accommodate for those differences, new hires are not allowed to have access to that interface until their official start date.</p><p>So, we needed an interface we could expose to new hires before their start date for them to provide this required data such that it would save directly into our people management software.</p><h3>Application architecture</h3><p>Let’s start with our people management software. It needed a way to alert our application that a new hire was ready to receive access to the onboarding form. While the software allows for robust customization with its own IDE, it is somewhat limited when it comes to interfacing with other systems. It relies on a pattern of outputting files somewhere for a dependent system to pick up to do what ever processing is necessary. In practice, it looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*HI7Chmu81Gn0qrC9yAFdhg.jpeg" /></figure><p>But the software does support GET requests. So we adopted SQS to allow the system to add new items to the queue. A lambda expression then runs on a timed looped to process new entries on the queue to give those new employees access to the onboarding form. The SQS queue is secured behind API Gateway, requiring an API key to be accessed. It ended up looking like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*byCqL6PIYodKqqe78DYBWg.png" /></figure><blockquote><strong><em>API Key? Why not IAM? </em></strong><em>Again, our people management software has very limited capabilities when it comes to interfacing with other systems. While it has it’s own IDE, it’s a drag-and-drop interface, not a text editor + compiler. The queue is only used to alert the system of new employees to be processed.</em></blockquote><p>At the other end of the application, the UI is a React app served up using Lambda and S3, with the <a href="https://serverless.com/">Serverless</a> framework, and relies on AWS Cognito to get IAM credentials to use our other APIs secured with API Gateway.</p><blockquote><strong><em>React app? Lambda? Why not just serve it directly out of S3? </em></strong><em>At time of writing, such an architecture would’ve meant making the S3 bucket publicly readable, which is something not acceptable to our internal security team. Also, as will be discussed later, having some amount of server side rendering will be helpful.</em></blockquote><p>In between the SQS queue and the UI, is an API to federate requests. This makes controlling access to our people management software easier, and it makes development of our UI simpler. Our people management software exposes its data primarily by means of a SOAP API, something not well supported in modern app development.</p><p>This API also controls which fields appear on the form for each country. So when the UI makes a request to the API, it gets a list of all the fields for the relevant country, with data prepopulated if we have it.</p><p>The API is a dockerized NodeJS app running in Fargate behind API Gateway that is secured with IAM permissions.</p><h4>Making it work</h4><p>Does any of this architecture sound appealing but unrealistic given your environment? We thought the same thing. But through research and experimentation we were successful.</p><p>Over the next four blog posts, we examine:</p><ul><li><a href="https://medium.com/expedia-engineering/designing-apis-to-be-modular-deployable-and-secure-76960c39d610"><strong>Designing APIs to be modular, deployable, and secure</strong></a></li><li><a href="https://medium.com/expedia-engineering/aws-cognito-aws-lambda-serverless-framework-react-with-redux-92cdfec83df2"><strong>AWS Cognito + AWS Lambda + Serverless Framework + React with Redux</strong></a></li><li><strong>Using API Gateway for Authorization and Authentication</strong></li><li><strong>Case Study in Modular Design</strong></li></ul><h4>Conclusion</h4><p>We’re looking forward to sharing what we’ve learned from over the last year and hope that you’ll be able to take our ideas and evolve them.</p><p>Please enjoy the next blog post <a href="https://medium.com/expedia-engineering/designing-apis-to-be-modular-deployable-and-secure-76960c39d610"><strong>Designing APIs to be modular, deployable, and secure</strong></a> by Sarah Purhar.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bceb1841cde" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expedia-group-tech/using-aws-managed-services-in-an-enterprise-environment-1bceb1841cde">Using AWS Managed Services in an Enterprise Environment</a> was originally published in <a href="https://medium.com/expedia-group-tech">Expedia Group Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>