<?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 Developer world on Medium]]></title>
        <description><![CDATA[Stories by Developer world on Medium]]></description>
        <link>https://medium.com/@talkto?source=rss-4045737d1d5c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7nts6z0DAEmJF46LJ8BjDw.png</url>
            <title>Stories by Developer world on Medium</title>
            <link>https://medium.com/@talkto?source=rss-4045737d1d5c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 09:25:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@talkto/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[Creating Lambda Functions]]></title>
            <link>https://medium.com/developerworld/creating-lambda-functions-d9c97bfcdadd?source=rss-4045737d1d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9c97bfcdadd</guid>
            <category><![CDATA[serverless-architecture]]></category>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Developer world]]></dc:creator>
            <pubDate>Sat, 07 Jul 2018 13:26:50 GMT</pubDate>
            <atom:updated>2018-07-07T13:51:10.389Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dTP1w-I_dAf7MCwf" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>In this Tutorial we are going to build a<em> lambda function</em> to process log files<em>.</em></blockquote><blockquote>This function will be triggered when a new log file is added to an <strong>S3</strong> bucket and the result of the Lambda function is to create an<strong> SNS </strong>notification if there is an error in the file</blockquote><ol><li>Browse the following link: <a href="https://console.aws.amazon.com/lambda">https://console.aws.amazon.com/lambda</a>. Select <strong>Get Started Now</strong> to start creating a new function:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*54Wg3RdwBRqn-iFgJIiU1A.png" /></figure><p>2.<strong> AWS</strong> offers many templates with sample configuration and code. For example, you could use a template of a<strong> Lambda function </strong>that processes bounced e-mails. This option is interesting for marketing campaigns to remove e-mail addresses that don’t exist. However, in this example, we will select a <strong><em>Blank Function</em></strong> template:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2QoVgUvVbp_RsbnmTK4aLQ.png" /></figure><p><strong>3. A Lambda </strong>function can be triggered by many different sources. In the next screen, you will see a list of all available options. Select <strong>S3</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*kxCAyvSUz4VqavwAEsO8sA.png" /></figure><p>4. After selecting <strong>S3</strong>, you will be presented with some configuration options. Select the bucket that we have created previously with the<strong> CLI</strong>. For the <strong>Event type</strong>, select <strong>Object Created (All)</strong> to trigger the function whenever a new file is created. For <strong>Prefix</strong>, type logs/ to consider only files in the logs folder and in the <strong>Suffix</strong>, type <strong>txt</strong> to consider only text files. Finally, check the <strong>Enable trigger</strong> option and click on Next:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*gpzV1gPKbab7IzRBAEF5Dw.png" /></figure><p>5. Type a name for your Lambda function, for example, <strong>processLog</strong>, and select the<strong> </strong><strong>Node.js 6.10</strong> option for Runtime:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*KC_cxleeME79vFLaIQ8Hrg.png" /></figure><p>6. Now we need to implement the code that will be executed by the Lambda function using the <strong>Edit code inline</strong>option. In this example, we are using S3.getObject to retrieve the file created and SNS.publish to create a notification if there is the error word in this file. For the SNS topic ARN, you can use the same that was previously created with the CLI:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84056b980e16d4d529b4f584aeacc22d/href">https://medium.com/media/84056b980e16d4d529b4f584aeacc22d/href</a></iframe><p>7. As we have used the inline option to write the code instead of uploading a ZIP file, the code will be placed inside an index.js file. Also, the module that we have created exports a function named handler. In this case, we need to configure the Lambda handler with the index.handler name. For the <strong>Role</strong> box, we need to create a new one because a Lambda function can&#39;t execute without proper access. Even if you create a Lambda using an administrator account, you must give explicit permissions for which kind of services and resources the Lambda will be able to access:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*ImbG-9UTxffdDFAUnnEg0A.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/890c670a24103adfb2530a1d51dafd6d/href">https://medium.com/media/890c670a24103adfb2530a1d51dafd6d/href</a></iframe><p>8. Type a role name for this role and click on <strong>Edit</strong> to modify the default policy document. Add the following JSON object and finish by clicking on <strong>Allow:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*k7WNy8tSU0_ipai0P-mkCg.png" /></figure><p>9. The last step is to configure the <strong>Advanced settings</strong>. Set the amount of RAM memory that should be allocated for this function and the timeout value that AWS must wait for this function to finish its execution. You may need to increase the timeout value depending on the size of the log files that you are going to use for testing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*w_bmprTFFiw39-1iTOPHAg.png" /></figure><p>10. Click on <strong>Next</strong> and you will be redirected to a <strong>Review</strong> page where you need to confirm the function creation</p><p>11. To test this function, we can use the Management Console, which lets us create custom input events, but, in this case, we can use the CLI to upload a new file and trigger the Lambda function. If the file has the word “error”, you should receive an e-mail message with the file name</p><blockquote><strong><em>aws s3 cp log1.txt s3://my-bucket-name/logs/</em></strong></blockquote><p>12. If you have any issues, you can try using the Management Console to see the error message that appears. In this case, use the following JSON object as the event trigger, replacing the bucket name</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60a20ec46240f9b510d7fc3952aea9a0/href">https://medium.com/media/60a20ec46240f9b510d7fc3952aea9a0/href</a></iframe><p>Follow the next story</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9c97bfcdadd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developerworld/creating-lambda-functions-d9c97bfcdadd">Creating Lambda Functions</a> was originally published in <a href="https://medium.com/developerworld">Developerworld</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Lambda Guide — Comparison Of Serverless Framework V.1 & V.0]]></title>
            <link>https://medium.com/developerworld/aws-lambda-guide-comparison-of-serverless-framework-v-1-v-0-4c2a854991fb?source=rss-4045737d1d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c2a854991fb</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Developer world]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 11:20:05 GMT</pubDate>
            <atom:updated>2018-07-06T11:20:05.169Z</atom:updated>
            <content:encoded><![CDATA[<p>After the 0.5.6 release of Serverless we sat down with many contributors and users of the Framework to discuss the next steps to improve Serverless.</p><p>Those discussions lead to our decision to completely rewrite Serverless. The configuration is in no way backwards compatible and can basically be seen as a completely new tool.</p><p>We’ve decided to make this step so in the future we have a stronger base to work from and make sure we don’t have to do major breaking changes like this anymore.</p><p>Let’s dig into the main differences between 0.x and 1.x to give you an idea how to start migrating your services. In general we’ve seen teams move from 0.x to 1.x in a relatively short amount of time, if you have any questions regarding the move please let us know in <a href="http://forum.serverless.com/">our Forum</a> or create <a href="https://github.com/serverless/serverless/issues">Issues in Github</a>.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/v0_to_v1/#main-differences-between-0x-and-1x">#</a>Main differences between 0.x and 1.x</h3><p>As 1.x is a complete reimplementation without backwards compatibility pretty much everything is different. The following features are the most important ones to give you an understanding of where Serverless is moving.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/v0_to_v1/#central-configuration-file">#</a>Central configuration file</h3><p>In the past configuration was spread out over several configuration files. It was hard for users to have a good overview over all the different configuration values set for different functions. This was now moved into a central serverless.yml file that stores all configuration for one service. This also means there is no specific folder setup that you have to follow any more. By default Serverless simply zips up the folder your serverless.yml is in and deploys it to any functions defined in that config file (although you can <a href="https://serverless.com/framework/docs/providers/aws/guide/packaging/">change the packaging behavior</a>).</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/v0_to_v1/#services-are-the-main-unit-of-deployment">#</a>Services are the main unit of deployment</h3><p>In the past Serverless didn’t create a strong connection between functions that were deployed together. It was more for convenience sake that separate functions were grouped together. With 1.x functions now belong to a service. You can implement and deploy different services and while it’s still possible to mix functions that are not related into the same service it’s discouraged. Serverless wants you to build a micro-service architecture with functions being a part of that, but not the only part. You can read more about this in a past <a href="https://serverless.com/blog/beginning-serverless-framework-v1/">blog post</a></p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/v0_to_v1/#built-on-cloudformation">#</a>Built on CloudFormation</h3><p>With the move to a more service oriented style came the decision to move all configuration into CloudFormation. Every resource we create gets created through a central CloudFormation template. Each service gets its own CloudFormation stack, we even deploy new CF stacks if you create a service in a different stage. A very important feature that came with this move to CF was that you can now easily create any other kind of resource in AWS and connect it with your functions. You can read more about resources in <a href="https://serverless.com/framework/docs/providers/aws/guide/resources/">our guide</a></p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/v0_to_v1/#new-plugin-system">#</a>New plugin system</h3><p>While our old plugin system allowed for a powerful setup we felt we could push it a lot further and went back to the drawing board. We came up with a completely new way to build plugins for Serverless through hooks and lifecycle events. This is a breaking change for any existing plugin. You can read more about our Plugin system in our <a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/">extending serverless docs</a>.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/v0_to_v1/#endpoints-are-now-events">#</a>Endpoints are now events</h3><p>In 0.x APIG was treated as a separate resource and you could deploy endpoints separately. In 1.x APIG is just another event source that can be configured to trigger Lambda functions. We create one APIG per CloudFormation stack, so if you deploy to different stages we’re creating separate API Gateways. You can read all about our <a href="https://serverless.com/framework/docs/providers/aws/events/apigateway/">APIG integration in our event docs</a>.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/v0_to_v1/#how-to-upgrade-from-0x-to-1x">#</a>How to upgrade from 0.x to 1.x</h3><p>As Serverless 1.x is a complete reimplementation and does not implement all the features that were in 0.x (but has a lot more features in general) there is no direct update path. Basically the best way for users to move from 0.x to 1.x is to go through <a href="https://serverless.com/framework/docs/providers/aws/guide/">our guide</a> and the <a href="https://serverless.com/framework/docs/providers/aws/">AWS provider documentation</a> that will teach you all the details of Serverless 1.x. This should make it pretty easy to understand how to set up a service for 1.x and move your code over. We’ve worked with different teams during the Beta phase of Serverless 1.x and they were able to move their services into the new release pretty quickly.</p><p><em>Originally published at </em><a href="https://serverless.com/framework/docs/providers/aws/guide/v0_to_v1/"><em>serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c2a854991fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developerworld/aws-lambda-guide-comparison-of-serverless-framework-v-1-v-0-4c2a854991fb">AWS Lambda Guide — Comparison Of Serverless Framework V.1 &amp; V.0</a> was originally published in <a href="https://medium.com/developerworld">Developerworld</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Lambda Guide — Serverless.yml Reference]]></title>
            <link>https://medium.com/developerworld/aws-lambda-guide-serverless-yml-reference-c5ed28e689a3?source=rss-4045737d1d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5ed28e689a3</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Developer world]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 11:18:07 GMT</pubDate>
            <atom:updated>2018-07-06T11:18:07.045Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/serverless/serverless/edit/master/docs/providers/aws/guide/serverless.yml.md">Edit on github</a></p><p>Here is a list of all available properties in serverless.yml when the provider is set to aws.</p><pre>service:  name: myService  awsKmsKeyArn: arn:aws:kms:us-east-1:XXXXXX:key/some-hash frameworkVersion: &quot;&gt;=1.0.0 &lt;2.0.0&quot; provider:  name: aws  runtime: nodejs6.10  stage: dev  region: us-east-1  stackName: custom-stack-name  apiName: custom-api-name  profile: production  memorySize: 512  timeout: 10  logRetentionInDays: 14  deploymentBucket:  name: com.serverless.${self:provider.region}.deploys  serverSideEncryption: AES256  role: arn:aws:iam::XXXXXX:role/role  cfnRole: arn:aws:iam::XXXXXX:role/role  versionFunctions: false  environment:  serviceEnvVar: 123456789  endpointType: regional  apiKeys:  - myFirstKey  - ${opt:stage}-myFirstKey  - ${env:MY_API_KEY}  apiGateway:  restApiId: xxxxxxxxxx  restApiRootResourceId: xxxxxxxxxx  restApiResources: &#39;/users&#39;: xxxxxxxxxx &#39;/users/create&#39;: xxxxxxxxxx  usagePlan:  quota:  limit: 5000  offset: 2  period: MONTH  throttle:  burstLimit: 200  rateLimit: 100  stackTags:  key: value  iamManagedPolicies:  - arn:aws:iam:*****:policy/some-managed-policy  iamRoleStatements:  - Effect: &#39;Allow&#39;  Action:  - &#39;s3:ListBucket&#39;  Resource:  Fn::Join:  - &#39;&#39;  - - &#39;arn:aws:s3:::&#39;  - Ref: ServerlessDeploymentBucket  stackPolicy:  - Effect: Allow  Principal: &quot;*&quot;  Action: &quot;Update:*&quot;  Resource: &quot;*&quot;  - Effect: Deny  Principal: &quot;*&quot;  Resource: &quot;*&quot;  Action:  - Update:Replace  - Update:Delete  Condition:  StringEquals:  ResourceType:  - AWS::EC2::Instance  vpc:  securityGroupIds:  - securityGroupId1  - securityGroupId2  subnetIds:  - subnetId1  - subnetId2  notificationArns:  - &#39;arn:aws:sns:us-east-1:XXXXXX:mytopic&#39;  resourcePolicy:  - Effect: Allow  Principal: &quot;*&quot;  Action: execute-api:Invoke  Resource:  - execute-api:/*/*/*  Condition:  IpAddress:  aws:SourceIp:  - &quot;123.123.123.123&quot;  tags:  foo: bar  baz: qux package:  include:  - src/**  - handler.js  exclude:  - .git/**  - .travis.yml  excludeDevDependencies: false  artifact: path/to/my-artifact.zip  individually: true functions:  usersCreate:  handler: users.create  name: ${self:provider.stage}-lambdaName  description: My function  memorySize: 512  runtime: nodejs6.10  timeout: 10  role: arn:aws:iam::XXXXXX:role/role  onError: arn:aws:sns:us-east-1:XXXXXX:sns-topic  awsKmsKeyArn: arn:aws:kms:us-east-1:XXXXXX:key/some-hash  environment:  functionEnvVar: 12345678  tags:  foo: bar  vpc:  securityGroupIds:  - securityGroupId1  - securityGroupId2  subnetIds:  - subnetId1  - subnetId2  package:  include:  - src/**  - handler.js  exclude:  - .git/**  - .travis.yml  artifact: path/to/my-artifact.zip  individually: true  events:  - http:  path: users/create  method: get  cors: true  private: true  authorizer:  name: authorizerFunc  arn: xxx:xxx:Lambda-Name  resultTtlInSeconds: 0  identitySource: method.request.header.Authorization  identityValidationExpression: someRegex  - s3:  bucket: photos  event: s3:ObjectCreated:*  rules:  - prefix: uploads/  - suffix: .jpg  - schedule:  name: my scheduled event  description: a description of my scheduled event&#39;s purpose  rate: rate(10 minutes)  enabled: false  input:  key1: value1  key2: value2  stageParams:  stage: dev  inputPath: &#39;$.stageVariables&#39;  - sns:  topicName: aggregate  displayName: Data aggregation pipeline  - stream:  arn: arn:aws:kinesis:region:XXXXXX:stream/foo  batchSize: 100  startingPosition: LATEST  enabled: false  - alexaSkill:  appId: amzn1.ask.skill.xx-xx-xx-xx  enabled: true  - alexaSmartHome:  appId: amzn1.ask.skill.xx-xx-xx-xx  enabled: true  - iot:  name: myIoTEvent  description: An IoT event  enabled: true  sql: &quot;SELECT * FROM &#39;some_topic&#39;&quot;  sqlVersion: beta  - cloudwatchEvent:  event:  source:  - &quot;aws.ec2&quot;  detail-type:  - &quot;EC2 Instance State-change Notification&quot;  detail:  state:  - pending  input:  key1: value1  key2: value2  stageParams:  stage: dev  inputPath: &#39;$.stageVariables&#39;  - cloudwatchLog:  logGroup: &#39;/aws/lambda/hello&#39;  filter: &#39;{$.userIdentity.type = Root}&#39;  - cognitoUserPool:  pool: MyUserPool  trigger: PreSignUp resources:  Resources:  usersTable:  Type: AWS::DynamoDB::Table  Properties:  TableName: usersTable  AttributeDefinitions:  - AttributeName: email  AttributeType: S  KeySchema:  - AttributeName: email  KeyType: HASH  ProvisionedThroughput:  ReadCapacityUnits: 1  WriteCapacityUnits: 1  Outputs:  UsersTableArn:  Description: The ARN for the User&#39;s Table  Value: &quot;Fn::GetAtt&quot;: [ usersTable, Arn ]  Export:  Name: ${self:service}:${opt:stage}:UsersTableArn</pre><p><em>Originally published at </em><a href="https://serverless.com/framework/docs/providers/aws/guide/serverless.yml/"><em>serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5ed28e689a3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developerworld/aws-lambda-guide-serverless-yml-reference-c5ed28e689a3">AWS Lambda Guide — Serverless.yml Reference</a> was originally published in <a href="https://medium.com/developerworld">Developerworld</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless Framework Guide — AWS Lambda — Workflow]]></title>
            <link>https://medium.com/developerworld/serverless-framework-guide-aws-lambda-workflow-807973c0b9a0?source=rss-4045737d1d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/807973c0b9a0</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Developer world]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 11:16:31 GMT</pubDate>
            <atom:updated>2018-07-06T11:16:31.990Z</atom:updated>
            <content:encoded><![CDATA[<p>Quick recommendations and tips for various processes.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/workflow/#development-workflow">#</a>Development Workflow</h3><ol><li>Write your functions</li><li>Use serverless deploy only when you&#39;ve made changes to serverless.yml and in CI/CD systems.</li><li>Use serverless deploy function -f myFunction to rapidly deploy changes when you are working on a specific AWS Lambda Function.</li><li>Use serverless invoke -f myFunction -l to test your AWS Lambda Functions on AWS.</li><li>Open up a separate tab in your console and stream logs in there via serverless logs -f myFunction -t.</li><li>Write tests to run locally.</li></ol><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/workflow/#using-stages">#</a>Using stages</h3><ul><li>At the very least, use a dev and production stage.</li><li>Use different AWS accounts for stages.</li><li>In larger teams, each member should use a separate AWS account and their own stage for development.</li></ul><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/workflow/#larger-projects">#</a>Larger Projects</h3><ul><li>Break your application/project into multiple Serverless Services.</li><li>Model your Serverless Services around Data Models or Workflows.</li><li>Keep the Functions and Resources in your Serverless Services to a minimum.</li></ul><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/workflow/#cheat-sheet">#</a>Cheat Sheet</h3><p>A handy list of commands to use when developing with the Serverless Framework.</p><p><a href="https://serverless.com/framework/docs/providers/aws/guide/workflow/#create-a-service">#</a>Create A Service:</p><p>Creates a new Service</p><pre>serverless create -p [SERVICE NAME] -t aws-nodejs</pre><p><a href="https://serverless.com/framework/docs/providers/aws/guide/workflow/#install-a-service">#</a>Install A Service</p><p>This is a convenience method to install a pre-made Serverless Service locally by downloading the Github repo and unzipping it.</p><pre>serverless install -u [GITHUB URL OF SERVICE]</pre><p><a href="https://serverless.com/framework/docs/providers/aws/guide/workflow/#deploy-all">#</a>Deploy All</p><p>Use this when you have made changes to your Functions, Events or Resources in serverless.yml or you simply want to deploy all changes within your Service at the same time.</p><pre>serverless deploy -s [STAGE NAME] -r [REGION NAME] -v</pre><p><a href="https://serverless.com/framework/docs/providers/aws/guide/workflow/#deploy-function">#</a>Deploy Function</p><p>Use this to quickly overwrite your AWS Lambda code on AWS, allowing you to develop faster.</p><pre>serverless deploy function -f [FUNCTION NAME] -s [STAGE NAME] -r [REGION NAME]</pre><p><a href="https://serverless.com/framework/docs/providers/aws/guide/workflow/#invoke-function">#</a>Invoke Function</p><p>Invokes an AWS Lambda Function on AWS and returns logs.</p><pre>serverless invoke -f [FUNCTION NAME] -s [STAGE NAME] -r [REGION NAME] -l</pre><p><a href="https://serverless.com/framework/docs/providers/aws/guide/workflow/#streaming-logs">#</a>Streaming Logs</p><p>Open up a separate tab in your console and stream all logs for a specific Function using this command.</p><pre>serverless logs -f [FUNCTION NAME] -s [STAGE NAME] -r [REGION NAME]</pre><p><em>Originally published at </em><a href="https://serverless.com/framework/docs/providers/aws/guide/workflow/"><em>serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=807973c0b9a0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developerworld/serverless-framework-guide-aws-lambda-workflow-807973c0b9a0">Serverless Framework Guide — AWS Lambda — Workflow</a> was originally published in <a href="https://medium.com/developerworld">Developerworld</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Lambda Guide — Plugins]]></title>
            <link>https://medium.com/developerworld/aws-lambda-guide-plugins-50547bda0e0f?source=rss-4045737d1d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/50547bda0e0f</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Developer world]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 11:14:14 GMT</pubDate>
            <atom:updated>2018-07-06T11:14:14.762Z</atom:updated>
            <content:encoded><![CDATA[<p>A Plugin is custom Javascript code that creates new or extends existing commands within the Serverless Framework. The Serverless Framework is merely a group of Plugins that are provided in the core. If you or your organization have a specific workflow, install a pre-written Plugin or write a plugin to customize the Framework to your needs. External Plugins are written exactly the same way as the core Plugins.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#installing-plugins">#</a>Installing Plugins</h3><p>External Plugins are added on a per service basis and are not applied globally. Make sure you are in your Service’s root directory, then install the corresponding Plugin with the help of NPM:</p><pre>npm install --save custom-serverless-plugin</pre><p>We need to tell Serverless that we want to use the plugin inside our service. We do this by adding the name of the Plugin to the plugins section in the serverless.yml file.</p><pre>plugins:  - custom-serverless-plugin</pre><p>The plugins section supports two formats:</p><p>Array object:</p><pre>plugins:  - plugin1  - plugin2</pre><p>Enhanced plugins object:</p><pre>plugins:  localPath: &#39;./custom_serverless_plugins&#39;  modules:  - plugin1  - plugin2</pre><p>Plugins might want to add extra information which should be accessible to Serverless. The custom section in the serverless.yml file is the place where you can add necessary configurations for your plugins (the plugins author / documentation will tell you if you need to add anything there):</p><pre>plugins:  - custom-serverless-plugin custom:  customkey: customvalue</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#service-local-plugin">#</a>Service local plugin</h3><p>If you are working on a plugin or have a plugin that is just designed for one project they can be loaded from the local folder. Local plugins can be added in the plugins array in serverless.yml.</p><p>By default local plugins can be added to the .serverless_plugins directory at the root of your service, and in the plugins array in serverless.yml.</p><pre>plugins:  - custom-serverless-plugin</pre><p>Local plugins folder can be changed by enhancing plugins object:</p><pre>plugins:  localPath: &#39;./custom_serverless_plugins&#39;  modules:  - custom-serverless-plugin</pre><p>The custom-serverless-plugin will be loaded from the custom_serverless_plugins directory at the root of your service. If the localPath is not provided or empty .serverless_plugins directory will be taken as the localPath.</p><p>The plugin will be loaded based on being named custom-serverless-plugin.js or custom-serverless-plugin\index.js in the root of localPath folder (.serverless_plugins by default).</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#load-order">#</a>Load Order</h3><p>Keep in mind that the order you define your plugins matters. When Serverless loads all the core plugins and then the custom plugins in the order you’ve defined them.</p><pre>plugins:  - plugin1  - plugin2</pre><p>In this case plugin1 is loaded before plugin2.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#writing-plugins">#</a>Writing Plugins</h3><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#concepts">#</a>Concepts</h3><h4><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#plugin">#</a>Plugin</h4><p>Code which defines <em>Commands</em>, any <em>Events</em> within a <em>Command</em>, and any <em>Hooks</em> assigned to a <em>Lifecycle Event</em>.</p><ul><li>Command // CLI configuration, commands, subcommands, options</li><li>LifecycleEvent(s) // Events that happen sequentially when the command is run</li><li>Hook(s) // Code that runs when a Lifecycle Event happens during a Command</li></ul><h4><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#command">#</a>Command</h4><p>A CLI <em>Command</em> that can be called by a user, e.g. serverless deploy. A Command has no logic, but simply defines the CLI configuration (e.g. command, subcommands, parameters) and the <em>Lifecycle Events</em> for the command. Every command defines its own lifecycle events.</p><pre>; class MyPlugin { constructor() { this.commands = { deploy: { lifecycleEvents: [ &#39;resources&#39;, &#39;functions&#39; ] }, }; } } module.exports = MyPlugin;</pre><h4><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#lifecycle-events">#</a>Lifecycle Events</h4><p>Events that fire sequentially during a Command. The above example lists two Events. However, for each Event, an additional before and after event is created. Therefore, six Events exist in the above example:</p><ul><li>before:deploy:resources</li><li>deploy:resources</li><li>after:deploy:resources</li><li>before:deploy:functions</li><li>deploy:functions</li><li>after:deploy:functions</li></ul><p>The name of the command in front of lifecycle events when they are used for Hooks.</p><h4><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#hooks">#</a>Hooks</h4><p>A Hook binds code to any lifecycle event from any command.</p><pre>; class Deploy { constructor() { this.commands = { deploy: { lifecycleEvents: [ &#39;resources&#39;, &#39;functions&#39; ] }, }; this.hooks = { &#39;before:deploy:resources&#39;: this.beforeDeployResources, &#39;deploy:resources&#39;: this.deployResources, &#39;after:deploy:functions&#39;: this.afterDeployFunctions }; } beforeDeployResources() { console.log(&#39;Before Deploy Resources&#39;); } deployResources() { console.log(&#39;Deploy Resources&#39;); } afterDeployFunctions() { console.log(&#39;After Deploy Functions&#39;); } } module.exports = Deploy;</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#nesting-commands">#</a>Nesting Commands</h3><p>You can also nest commands, e.g. if you want to provide a command serverless deploy function. Those nested commands have their own lifecycle events and do not inherit them from their parents.</p><pre>; class MyPlugin { constructor() { this.commands = { deploy: { lifecycleEvents: [ &#39;resources&#39;, &#39;functions&#39; ], commands: { function: { lifecycleEvents: [ &#39;package&#39;, &#39;deploy&#39; ], }, }, }, } } } module.exports = MyPlugin;</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#defining-options">#</a>Defining Options</h3><p>Each (sub)command can have multiple Options.</p><p>Options are passed in with a double dash (--) like this: serverless function deploy --function functionName.</p><p>Option Shortcuts are passed in with a single dash (-) like this: serverless function deploy -f functionName.</p><p>The options object will be passed in as the second parameter to the constructor of your plugin.</p><p>In it, you can optionally add a shortcut property, as well as a required property. The Framework will return an error if a required Option is not included. You can also set a default property if your option is not required.</p><p><strong>Note:</strong> At this time, the Serverless Framework does not use parameters.</p><pre>; class Deploy { constructor(serverless, options) { this.serverless = serverless; this.options = options; this.commands = { deploy: { lifecycleEvents: [ &#39;functions&#39; ], options: { function: { usage: &#39;Specify the function you want to deploy (e.g. &quot;--function myFunction&quot;)&#39;, shortcut: &#39;f&#39;, required: true }, stage: { usage: &#39;Specify the stage you want to deploy to. (e.g. &quot;--stage prod&quot;)&#39;, shortcut: &#39;s&#39;, default: &#39;dev&#39; } } }, }; this.hooks = { &#39;deploy:functions&#39;: this.deployFunction.bind(this) } } deployFunction() { console.log(&#39;Deploying function: &#39;, this.options.function); } } module.exports = Deploy;</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#provider-specific-plugins">#</a>Provider Specific Plugins</h3><p>Plugins can be provider specific which means that they are bound to a provider.</p><p><strong>Note:</strong> Binding a plugin to a provider is optional. Serverless will always consider your plugin if you don’t specify a provider.</p><p>The provider definition should be added inside the plugins constructor:</p><pre>; class ProviderDeploy { constructor(serverless, options) { this.serverless = serverless; this.options = options; this.provider = this.serverless.getProvider(&#39;providerName&#39;); this.commands = { deploy: { lifecycleEvents: [ &#39;functions&#39; ], options: { function: { usage: &#39;Specify the function you want to deploy (e.g. &quot;--function myFunction&quot;)&#39;, required: true } } }, }; this.hooks = { &#39;deploy:functions&#39;: this.deployFunction.bind(this) } } deployFunction() { console.log(&#39;Deploying function: &#39;, this.options.function); } } module.exports = ProviderDeploy;</pre><p>The Plugin’s functionality will now only be executed when the Serverless Service’s provider matches the provider name which is defined inside the plugins constructor.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#serverless-instance">#</a>Serverless Instance</h3><p>The serverless instance which enables access to global service config during runtime is passed in as the first parameter to the plugin constructor.</p><pre>; class MyPlugin { constructor(serverless, options) { this.serverless = serverless; this.options = options; this.commands = { log: { lifecycleEvents: [ &#39;serverless&#39; ], }, }; this.hooks = { &#39;log:serverless&#39;: this.logServerless.bind(this) } } logServerless() { console.log(&#39;Serverless instance: &#39;, this.serverless); } } module.exports = MyPlugin;</pre><p><strong>Note:</strong> <a href="https://serverless.com/framework/docs/providers/aws/guide/variables.md#reference-properties-in-serverlessyml">Variable references</a> in the serverless instance are not resolved before a Plugin&#39;s constructor is called, so if you need these, make sure to wait to access those from your <a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#hooks">hooks</a>.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#command-naming">#</a>Command Naming</h3><p>Command names need to be unique. If we load two commands and both want to specify the same command (e.g. we have an integrated command deploy and an external command also wants to use deploy) the Serverless CLI will print an error and exit. If you want to have your own deploy command you need to name it something different like myCompanyDeploy so they don&#39;t clash with existing plugins.</p><p>The info command which is used to display information about the deployment has detailed lifecycleEvents you can hook into to add and display custom information.</p><p>Here’s an example overview of the info lifecycle events the AWS implementation exposes:</p><pre>-&gt; info:info -&gt; aws:info:validate -&gt; aws:info:gatherData -&gt; aws:info:displayServiceInfo -&gt; aws:info:displayApiKeys -&gt; aws:info:displayEndpoints -&gt; aws:info:displayFunctions -&gt; aws:info:displayStackOutputs</pre><p>Here you could e.g. hook into after:aws:info:gatherData and implement your own data collection and display it to the user.</p><p><strong>Note:</strong> Every provider implements its own info plugin so you might want to take a look into the lifecycleEvents the provider info plugin exposes.</p><p><em>Originally published at </em><a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/"><em>serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50547bda0e0f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developerworld/aws-lambda-guide-plugins-50547bda0e0f">AWS Lambda Guide — Plugins</a> was originally published in <a href="https://medium.com/developerworld">Developerworld</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Lambda Guide — IAM]]></title>
            <link>https://medium.com/developerworld/aws-lambda-guide-iam-892de6ec725b?source=rss-4045737d1d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/892de6ec725b</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Developer world]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 11:11:01 GMT</pubDate>
            <atom:updated>2018-07-06T11:11:01.203Z</atom:updated>
            <content:encoded><![CDATA[<p>Every AWS Lambda function needs permission to interact with other AWS infrastructure resources within your account. These permissions are set via an AWS IAM Role which the Serverless Framework automatically creates for each Serverless Service, and is shared by all of your Functions. The Framework allows you to modify this Role or create Function-specific Roles, easily.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/iam/#the-default-iam-role">#</a>The Default IAM Role</h3><p>By default, one IAM Role is shared by all of the Lambda functions in your service. Also by default, your Lambda functions have permission to create and write to CloudWatch logs. When VPC configuration is provided the default AWS AWSLambdaVPCAccessExecutionRole will be associated in order to communicate with your VPC resources.</p><p>To add specific rights to this service-wide Role, define statements in provider.iamRoleStatements which will be merged into the generated policy. As those statements will be merged into the CloudFormation template, you can use Join, Ref or any other CloudFormation method or feature.</p><pre>service: new-service provider:  name: aws  iamRoleStatements:  - Effect: &quot;Allow&quot;  Action:  - &quot;s3:ListBucket&quot;  Resource:  Fn::Join:  - &quot;&quot;  - - &quot;arn:aws:s3:::&quot;  - Ref: ServerlessDeploymentBucket  - Effect: &quot;Allow&quot;  Action:  - &quot;s3:PutObject&quot;  Resource:  Fn::Join:  - &quot;&quot;  - - &quot;arn:aws:s3:::&quot;  - Ref: ServerlessDeploymentBucket  - &quot;/*&quot;</pre><p>Alongside provider.iamRoleStatements managed policies can also be added to this service-wide Role, define managed policies in provider.iamManagedPolicies. These will also be merged into the generated IAM Role so you can use Join, Ref or any other CloudFormation method or feature here too.</p><pre>service: new-service provider:  name: aws  iamManagedPolicies:  - &#39;some:aws:arn:xxx:*:*&#39;  - &#39;someOther:aws:arn:xxx:*:*&#39;  - { &#39;Fn::Join&#39;: [&#39;:&#39;, [&#39;arn:aws:iam:&#39;, { Ref: &#39;AWSAccountId&#39; }, &#39;some/path&#39;]] }</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/iam/#custom-iam-roles">#</a>Custom IAM Roles</h3><p><strong>WARNING:</strong> You need to take care of the overall role setup as soon as you define custom roles.</p><p>That means that iamRoleStatements you&#39;ve defined on the provider level won&#39;t be applied anymore. Furthermore, you need to provide the corresponding permissions for your Lambdas logs and <a href="https://serverless.com/framework/docs/providers/aws/events/streams">stream</a> events.</p><p>Serverless empowers you to define custom roles and apply them to your functions on a provider or individual function basis. To do this, you must declare a role attribute at the level at which you would like the role to be applied.</p><p>Defining it on the provider will make the role referenced by the role value the default role for any Lambda without its own role declared. This is to say that defining a role attribute on individual functions will override any provider level declared role. If every function within your service has a role assigned to it (either via provider level role declaration, individual declarations, or a mix of the two) then the default role and policy will not be generated and added to your Cloud Formation Template.</p><p>The role attribute can have a value of the logical name of the role, the ARN of the role, or an object that will resolve in the ARN of the role. The declaration { function: { role: &#39;myRole&#39; } } will result in { &#39;Fn::GetAtt&#39;: [&#39;myRole&#39;, &#39;Arn&#39;] }. You can of course just declare an ARN like so { function: { role: &#39;an:aws:arn:xxx:*:*&#39; } }. This use case is primarily for those who must create their roles and / or policies via a means outside of Serverless.</p><p>Here are some examples of using these capabilities to specify Lambda roles.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/iam/#one-custom-iam-role-for-all-functions">#</a>One Custom IAM Role For All Functions</h3><pre>service: new-service provider:  name: aws  role: myDefaultRole  role: arn:aws:iam::0123456789:role//my/default/path/roleInMyAccount  role:  Fn::GetAtt:  - myRole  - Arn functions:  func0: ...  func1: ... resources:  Resources:  myDefaultRole:  Type: AWS::IAM::Role  Properties:  Path: /my/default/path/  RoleName: MyDefaultRole  AssumeRolePolicyDocument:  Version: &#39;2017&#39;  Statement:  - Effect: Allow  Principal:  Service:  - lambda.amazonaws.com  Action: sts:AssumeRole  ManagedPolicyArns:  - arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole  Policies:  - PolicyName: myPolicyName  PolicyDocument:  Version: &#39;2017&#39;  Statement:  - Effect: Allow  Action:  - logs:CreateLogGroup  - logs:CreateLogStream  - logs:PutLogEvents  Resource:  - &#39;Fn::Join&#39;:  - &#39;:&#39;  -  - &#39;arn:aws:logs&#39;  - Ref: &#39;AWS::Region&#39;  - Ref: &#39;AWS::AccountId&#39;  - &#39;log-group:/aws/lambda/*:*:*&#39;  - Effect: &quot;Allow&quot;  Action:  - &quot;s3:PutObject&quot;  Resource:  Fn::Join:  - &quot;&quot;  - - &quot;arn:aws:s3:::&quot;  - &quot;Ref&quot; : &quot;ServerlessDeploymentBucket&quot;</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/iam/#custom-iam-roles-for-each-function">#</a>Custom IAM Roles For Each Function</h3><pre>service: new-service provider:  name: aws ... functions:  func0:  role: myCustRole0 ...  func1:  role: myCustRole1 ... resources:  Resources:  myCustRole0:  Type: AWS::IAM::Role  Properties:  Path: /my/cust/path/  RoleName: MyCustRole0  AssumeRolePolicyDocument:  Version: &#39;2017&#39;  Statement:  - Effect: Allow  Principal:  Service:  - lambda.amazonaws.com  Action: sts:AssumeRole  Policies:  - PolicyName: myPolicyName  PolicyDocument:  Version: &#39;2017&#39;  Statement:  - Effect: Allow  Action:  - logs:CreateLogGroup  - logs:CreateLogStream  - logs:PutLogEvents  Resource:  - &#39;Fn::Join&#39;:  - &#39;:&#39;  -  - &#39;arn:aws:logs&#39;  - Ref: &#39;AWS::Region&#39;  - Ref: &#39;AWS::AccountId&#39;  - &#39;log-group:/aws/lambda/*:*:*&#39;  - Effect: Allow  Action:  - ec2:CreateNetworkInterface  - ec2:DescribeNetworkInterfaces  - ec2:DetachNetworkInterface  - ec2:DeleteNetworkInterface  Resource: &quot;*&quot;  myCustRole1:  Type: AWS::IAM::Role  Properties:  Path: /my/cust/path/  RoleName: MyCustRole1  AssumeRolePolicyDocument:  Version: &#39;2017&#39;  Statement:  - Effect: Allow  Principal:  Service:  - lambda.amazonaws.com  Action: sts:AssumeRole  Policies:  - PolicyName: myPolicyName  PolicyDocument:  Version: &#39;2017&#39;  Statement:  - Effect: Allow  Action:  - logs:CreateLogGroup  - logs:CreateLogStream  - logs:PutLogEvents  Resource:  - &#39;Fn::Join&#39;:  - &#39;:&#39;  -  - &#39;arn:aws:logs&#39;  - Ref: &#39;AWS::Region&#39;  - Ref: &#39;AWS::AccountId&#39;  - &#39;log-group:/aws/lambda/*:*:*&#39;  - Effect: &quot;Allow&quot;  Action:  - &quot;s3:PutObject&quot;  Resource:  Fn::Join:  - &quot;&quot;  - - &quot;arn:aws:s3:::&quot;  - &quot;Ref&quot; : &quot;ServerlessDeploymentBucket&quot;</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/iam/#a-custom-default-role--custom-function-roles">#</a>A Custom Default Role &amp; Custom Function Roles</h3><pre>service: new-service provider:  name: aws  role: myDefaultRole functions:  func0:  role: myCustRole0 ...  func1: ... resources:  Resources:  myDefaultRole:  Type: AWS::IAM::Role  Properties:  Path: /my/default/path/  RoleName: MyDefaultRole  AssumeRolePolicyDocument:  Version: &#39;2017&#39;  Statement:  - Effect: Allow  Principal:  Service:  - lambda.amazonaws.com  Action: sts:AssumeRole  Policies:  - PolicyName: myPolicyName  PolicyDocument:  Version: &#39;2017&#39;  Statement:  - Effect: Allow  Action:  - logs:CreateLogGroup  - logs:CreateLogStream  - logs:PutLogEvents  Resource:  - &#39;Fn::Join&#39;:  - &#39;:&#39;  -  - &#39;arn:aws:logs&#39;  - Ref: &#39;AWS::Region&#39;  - Ref: &#39;AWS::AccountId&#39;  - &#39;log-group:/aws/lambda/*:*:*&#39;  - Effect: &quot;Allow&quot;  Action:  - &quot;s3:PutObject&quot;  Resource:  Fn::Join:  - &quot;&quot;  - - &quot;arn:aws:s3:::&quot;  - &quot;Ref&quot; : &quot;ServerlessDeploymentBucket&quot;  myCustRole0:  Type: AWS::IAM::Role  Properties:  Path: /my/cust/path/  RoleName: MyCustRole0  AssumeRolePolicyDocument:  Version: &#39;2017&#39;  Statement:  - Effect: Allow  Principal:  Service:  - lambda.amazonaws.com  Action: sts:AssumeRole  Policies:  - PolicyName: myPolicyName  PolicyDocument:  Version: &#39;2017&#39;  Statement:  - Effect: Allow  Action:  - logs:CreateLogGroup  - logs:CreateLogStream  - logs:PutLogEvents  Resource:  - &#39;Fn::Join&#39;:  - &#39;:&#39;  -  - &#39;arn:aws:logs&#39;  - Ref: &#39;AWS::Region&#39;  - Ref: &#39;AWS::AccountId&#39;  - &#39;log-group:/aws/lambda/*:*:*&#39;  - Effect: Allow  Action:  - ec2:CreateNetworkInterface  - ec2:DescribeNetworkInterfaces  - ec2:DetachNetworkInterface  - ec2:DeleteNetworkInterface  Resource: &quot;*&quot;</pre><p><em>Originally published at </em><a href="https://serverless.com/framework/docs/providers/aws/guide/iam/"><em>serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=892de6ec725b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developerworld/aws-lambda-guide-iam-892de6ec725b">AWS Lambda Guide — IAM</a> was originally published in <a href="https://medium.com/developerworld">Developerworld</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless Framework Guide — AWS Lambda Guide — Packaging]]></title>
            <link>https://medium.com/developerworld/serverless-framework-guide-aws-lambda-guide-packaging-59b1d48223d0?source=rss-4045737d1d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/59b1d48223d0</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Developer world]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 11:08:55 GMT</pubDate>
            <atom:updated>2018-07-06T11:08:55.703Z</atom:updated>
            <content:encoded><![CDATA[<p>Using the Serverless CLI tool, you can package your project without deploying it to AWS. This is best used with CI / CD workflows to ensure consistent deployable artifacts.</p><p>Running the following command will build and save all of the deployment artifacts in the service’s .serverless directory:</p><pre>serverless package</pre><p>However, you can also use the — package option to add a destination path and Serverless will store your deployment artifacts there (../my-artifacts in the following case):</p><pre>serverless package --package my-artifacts</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/packaging/#package-configuration">#</a>Package Configuration</h3><p>Sometimes you might like to have more control over your function artifacts and how they are packaged.</p><p>You can use the package and exclude configuration for more control over the packaging process.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/packaging/#exclude--include">#</a>Exclude / include</h3><p>Exclude and include allows you to define globs that will be excluded / included from the resulting artifact. If you wish to include files you can use a glob pattern prefixed with ! such as !re-include-me/** in exclude or the dedicated include config. Serverless will run the glob patterns in order.</p><p>At first it will apply the globs defined in exclude. After that it&#39;ll add all the globs from include. This way you can always re-include previously excluded files and directories.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/packaging/#examples">#</a>Examples</h3><p>Exclude all node_modules but then re-include a specific modules (in this case node-fetch) using exclude exclusively</p><pre>package:  exclude:  - node_modules/**  - &#39;!node_modules/node-fetch/**&#39;</pre><p>Exclude all files but handler.js using exclude and include</p><pre>package:  exclude:  - src/**  include:  - src/function/handler.js</pre><p><strong>Note:</strong> Don’t forget to use the correct glob syntax if you want to exclude directories</p><pre>exclude: - tmp/** - .git/**</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/packaging/#artifact">#</a>Artifact</h3><p>For complete control over the packaging process you can specify your own artifact zip file. Serverless won’t zip your service if this is configured and therefore exclude and include will be ignored. Either you use artifact or include / exclude.</p><p>The artifact option is especially useful in case your development environment allows you to generate a deployable artifact like Maven does for Java.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/packaging/#example">#</a>Example</h3><pre>service: my-service package:  artifact: path/to/my-artifact.zip</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/packaging/#packaging-functions-separately">#</a>Packaging functions separately</h3><p>If you want even more controls over your functions for deployment you can configure them to be packaged independently. This allows you more control for optimizing your deployment. To enable individual packaging set individually to true in the service or function wide packaging settings.</p><p>Then for every function you can use the same exclude, include or artifact config options as you can service wide. The exclude and include option will be merged with the service wide options to create one exclude and include config per function during packaging.</p><pre>service: my-service package:  individually: true  exclude:  - excluded-by-default.json functions:  hello:  handler: handler.hello  package:  include:  - excluded-by-default.json  world:  handler: handler.hello  package:  exclude:  - some-file.js</pre><p>You can also select which functions to be packaged separately, and have the rest use the service package by setting the individually flag at the function level:</p><pre>service: my-service functions:  hello:  handler: handler.hello  world:  handler: handler.hello  package:  individually: true</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/packaging/#development-dependencies">#</a>Development dependencies</h3><p>Serverless will auto-detect and exclude development dependencies based on the runtime your service is using.</p><p>This ensures that only the production relevant packages and modules are included in your zip file. Doing this drastically reduces the overall size of the deployment package which will be uploaded to the cloud provider.</p><p>You can opt-out of automatic dev dependency exclusion by setting the excludeDevDependencies package config to false:</p><pre>package:  excludeDevDependencies: false</pre><p><em>Originally published at </em><a href="https://serverless.com/framework/docs/providers/aws/guide/packaging/"><em>serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59b1d48223d0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developerworld/serverless-framework-guide-aws-lambda-guide-packaging-59b1d48223d0">Serverless Framework Guide — AWS Lambda Guide — Packaging</a> was originally published in <a href="https://medium.com/developerworld">Developerworld</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless Variables]]></title>
            <link>https://medium.com/developerworld/serverless-variables-e0a7af76e840?source=rss-4045737d1d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0a7af76e840</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Developer world]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 11:07:00 GMT</pubDate>
            <atom:updated>2018-07-06T11:07:00.076Z</atom:updated>
            <content:encoded><![CDATA[<p>Variables allow users to dynamically replace config values in serverless.yml config.</p><p>They are especially useful when providing secrets for your service to use and when you are working with multiple stages.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#syntax">#</a>Syntax</h3><p>To use variables, you will need to reference values enclosed in ${} brackets.</p><pre>yamlKeyXYZ: ${variableSource} otherYamlKey: ${variableSource, defaultValue}</pre><p>You can define your own variable syntax (regex) if it conflicts with CloudFormation’s syntax.</p><p><strong>Note:</strong> You can only use variables in serverless.yml property <strong>values</strong>, not property keys. So you can&#39;t use variables to generate dynamic logical IDs in the custom resources section for example.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#current-variable-sources">#</a>Current variable sources:</h3><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#recursively-reference-properties">#</a>Recursively reference properties</h3><p>You can also <strong>Recursively reference properties</strong> with the variable system. This means you can combine multiple values and variable sources for a lot of flexibility.</p><p>For example:</p><pre>provider:  name: aws  stage: ${opt:stage, &#39;dev&#39;}  environment:  MY_SECRET: ${file(../config.${self:provider.stage}.json):CREDS}</pre><p>If sls deploy --stage qa is ran, the option stage=qa is used inside the ${file(../config.${self:provider.stage}.json):CREDS} variable and it will resolve the config.qa.json file and use the CREDS key defined.</p><p><strong>How that works:</strong></p><ol><li>stage is set to qa from the option supplied to the sls deploy --stage qa command</li><li>${self:provider.stage} resolves to qa and is used in ${file(../config.${self:provider.stage}.json):CREDS}</li><li>${file(../config.qa.json):CREDS} is found &amp; the CREDS value is read</li><li>MY_SECRET value is set</li></ol><p>Likewise, if sls deploy --stage prod is ran the config.prod.json file would be found and used.</p><p>If no --stage flag is provided, the second parameter defined in ${opt:stage, &#39;dev&#39;} a.k.a dev will be used and result in ${file(../config.dev.json):CREDS}.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#reference-properties-in-serverlessyml">#</a>Reference Properties In serverless.yml</h3><p>To self-reference properties in serverless.yml, use the ${self:someProperty} syntax in your serverless.yml. someProperty can contain the empty string for a top-level self-reference or a dotted attribute reference to any depth of attribute, so you can go as shallow or deep in the object tree as you want.</p><pre>service: new-service provider: aws custom:  globalSchedule: rate(10 minutes)  newService: ${self:}  exportName: ${self:custom.newService.service}-export functions:  hello:  handler: handler.hello  events:  - schedule: ${self:custom.globalSchedule}  world:  handler: handler.world  events:  - schedule: ${self:custom.globalSchedule} resources:  Outputs:  NewServiceExport:  Value: &#39;A Value To Export&#39;  Export:  Name: ${self:custom.exportName}</pre><p>In the above example you’re setting a global schedule for all functions by referencing the globalSchedule property in the same serverless.yml file. This way, you can easily change the schedule for all functions whenever you like.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#referencing-environment-variables">#</a>Referencing Environment Variables</h3><p>To reference environment variables, use the ${env:SOME_VAR} syntax in your serverless.yml configuration file. It is valid to use the empty string in place of SOME_VAR. This looks like &quot;${env:}&quot; and the result of declaring this in your serverless.yml is to embed the complete process.env object (i.e. all the variables defined in your environment).</p><p><strong>Note:</strong></p><p>Keep in mind that sensitive information which is provided through environment variables can be written into less protected or publicly accessible build logs, CloudFormation templates, et cetera.</p><pre>service: new-service provider: aws functions:  hello:  name: ${env:FUNC_PREFIX}-hello  handler: handler.hello  world:  name: ${env:FUNC_PREFIX}-world  handler: handler.world</pre><p>In the above example you’re dynamically adding a prefix to the function names by referencing the FUNC_PREFIX env var. So you can easily change that prefix for all functions by changing the FUNC_PREFIX env var.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#referencing-cli-options">#</a>Referencing CLI Options</h3><p>To reference CLI options that you passed, use the ${opt:some_option} syntax in your serverless.yml configuration file. It is valid to use the empty string in place of some_option. This looks like &quot;${opt:}&quot; and the result of declaring this in your serverless.yml is to embed the complete options object (i.e. all the command line options from your serverless command).</p><pre>service: new-service provider: aws functions:  hello:  name: ${opt:stage}-hello  handler: handler.hello  world:  name: ${opt:stage}-world  handler: handler.world</pre><p>In the above example, you’re dynamically adding a prefix to the function names by referencing the stage option that you pass in the CLI when you run serverless deploy --stage dev. So when you deploy, the function name will always include the stage you&#39;re deploying to.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#reference-cloudformation-outputs">#</a>Reference CloudFormation Outputs</h3><p>You can reference CloudFormation stack output values as the source of your variables to use in your service with the cf:stackName.outputKey syntax. For example:</p><pre>service: new-service provider: aws functions:  hello:  name: ${cf:another-service-dev.functionPrefix}-hello  handler: handler.hello  world:  name: ${cf:another-stack.functionPrefix}-world  handler: handler.world</pre><p>In that case, the framework will fetch the values of those functionPrefix outputs from the provided stack names and populate your variables. There are many use cases for this functionality and it allows your service to communicate with other services/stacks.</p><p>You can reference <a href="http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html">CloudFormation stack outputs export values</a> as well. For example:</p><pre>Outputs:  DynamoDbTable:  Value:  &quot;Ref&quot;: DynamoDbTable  Export:  Name: DynamoDbTable-${self:custom.stage} provider:  environment:  Table: &#39;Fn::ImportValue&#39;: &#39;DynamoDbTable-${self:custom.stage}&#39;</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#referencing-s3-objects">#</a>Referencing S3 Objects</h3><p>You can reference S3 values as the source of your variables to use in your service with the s3:bucketName/key syntax. For example:</p><pre>service: new-service provider: aws functions:  hello:  name: ${s3:myBucket/myKey}-hello  handler: handler.hello</pre><p>In the above example, the value for myKey in the myBucket S3 bucket will be looked up and used to populate the variable.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#reference-variables-using-the-ssm-parameter-store">#</a>Reference Variables using the SSM Parameter Store</h3><p>You can reference SSM Parameters as the source of your variables with the ssm:/path/to/param syntax. For example:</p><pre>service: ${ssm:/path/to/service/id}-service provider:  name: aws functions:  hello:  name: ${ssm:/path/to/service/myParam}-hello  handler: handler.hello</pre><p>In the above example, the value for the SSM Parameters will be looked up and used to populate the variables.</p><p>You can also reference encrypted SSM Parameters, of type SecureString, using the extended syntax, ssm:/path/to/secureparam~true.</p><pre>service: new-service provider: aws functions:  hello:  name: hello  handler: handler.hello custom:  supersecret: ${ssm:/path/to/secureparam~true}</pre><p>In this example, the serverless variable will contain the decrypted value of the SecureString.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#reference-variables-in-other-files">#</a>Reference Variables in Other Files</h3><p>You can reference variables in other YAML or JSON files. To reference variables in other YAML files use the ${file(../myFile.yml):someProperty} syntax in your serverless.yml configuration file. To reference variables in other JSON files use the ${file(../myFile.json):someProperty} syntax. It is important that the file you are referencing has the correct suffix, or file extension, for its file type (.yml for YAML or .json for JSON) in order for it to be interpreted correctly. Here&#39;s an example:</p><pre>globalSchedule: rate(10 minutes)</pre><pre>service: new-service provider: aws custom: ${file(../myCustomFile.yml)} functions:  hello:  handler: handler.hello  events:  - schedule: ${file(../myCustomFile.yml):globalSchedule}  world:  handler: handler.world  events:  - schedule: ${self:custom.globalSchedule}</pre><p>In the above example, you’re referencing the entire myCustomFile.yml file in the custom property. You need to pass the path relative to your service directory. You can also request specific properties in that file as shown in the schedule property. It&#39;s completely recursive and you can go as deep as you want. Additionally you can request properties that contain arrays from either YAML or JSON reference files. Here&#39;s a YAML example for an events array:</p><pre>myevents:  - schedule:  rate: rate(1 minute)</pre><p>and for JSON:</p><pre>{ &quot;myevents&quot;: [{ &quot;schedule&quot; : { &quot;rate&quot; : &quot;rate(1 minute)&quot; } }] }</pre><p>In your serverless.yml, depending on the type of your source file, either have the following syntax for YAML:</p><pre>functions:  hello:  handler: handler.hello  events: ${file(../myCustomFile.yml):myevents}</pre><p>or for a JSON reference file use this sytax:</p><pre>functions:  hello:  handler: handler.hello  events: ${file(../myCustomFile.json):myevents}</pre><p><strong>Note:</strong> If the referenced file is a symlink, the targeted file will be read.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#reference-variables-in-javascript-files">#</a>Reference Variables in Javascript Files</h3><p>You can reference JavaScript files to add dynamic data into your variables.</p><p>References can be either named or unnamed exports. To use the exported someModule in myFile.js you&#39;d use the following code ${file(../myFile.js):someModule}. For an unnamed export you&#39;d write ${file(../myFile.js)}. The first argument to your export will be a reference to the Serverless object, containing your configuration.</p><p>Here are other examples:</p><pre>module.exports.rate = () =&gt; { return &#39;rate (10 minutes)&#39;; }</pre><pre>module.exports = (serverless) =&gt; { serverless.cli.consoleLog(&#39;You can access Serverless config and methods as well!&#39;); return { property1: &#39;some value&#39;, property2: &#39;some other value&#39; } }</pre><pre>service: new-service provider: aws custom: ${file(../config.js)} functions:  hello:  handler: handler.hello  events:  - schedule: ${file(../scheduleConfig.js):rate}</pre><p>You can also return an object and reference a specific property. Just make sure you are returning a valid object and referencing a valid property:</p><pre>service: new-service provider: aws functions:  scheduledFunction:  handler: handler.scheduledFunction  events:  - schedule: ${file(../myCustomFile.js):schedule.ten}</pre><pre>module.exports.schedule = () =&gt; { return { ten: &#39;rate(10 minutes)&#39;, twenty: &#39;rate(20 minutes)&#39;, thirty: &#39;rate(30 minutes)&#39; }; }</pre><p>If your use case requires handling dynamic/async data sources (ie. DynamoDB, API calls…etc), you can also return a Promise that would be resolved as the value of the variable:</p><pre>service: new-service provider: aws functions:  scheduledFunction:  handler: handler.scheduledFunction  events:  - schedule: ${file(../myCustomFile.js):promised}</pre><pre>module.exports.promised = () =&gt; { return Promise.resolve(&#39;rate(10 minutes)&#39;); }</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#multiple-configuration-files">#</a>Multiple Configuration Files</h3><p>Adding many custom resources to your serverless.yml file could bloat the whole file, so you can use the Serverless Variable syntax to split this up.</p><pre>resources:  Resources: ${file(cloudformation-resources.json)}</pre><p>The corresponding resources which are defined inside the cloudformation-resources.json file will be resolved and loaded into the Resources section.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#nesting-variable-references">#</a>Nesting Variable References</h3><p>The Serverless variable system allows you to nest variable references within each other for ultimate flexibility. So you can reference certain variables based on other variables. Here’s an example:</p><pre>service: new-service provider: aws custom:  myFlexibleArn: ${env:${opt:stage}_arn} functions:  hello:  handler: handler.hello</pre><p>In the above example, if you pass dev as a stage option, the framework will look for the dev_arn environment variable. If you pass production, the framework will look for production_arn, and so on. This allows you to creatively use multiple variables by using a certain naming pattern without having to update the values of these variables constantly. You can go as deep as you want in your nesting, and can reference variables at any level of nesting from any source (env, opt, self or file).</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#overwriting-variables">#</a>Overwriting Variables</h3><p>The Serverless framework gives you an intuitive way to reference multiple variables as a fallback strategy in case one of the variables is missing. This way you’ll be able to use a default value from a certain source, if the variable from another source is missing.</p><p>For example, if you want to reference the stage you’re deploying to, but you don’t want to keep on providing the stage option in the CLI. What you can do in serverless.yml is:</p><pre>service: new-service provider:  name: aws  stage: dev custom:  myStage: ${opt:stage, self:provider.stage}  myRegion: ${opt:region, &#39;us-west-1&#39;} functions:  hello:  handler: handler.hello</pre><p>What this says is to use the stage CLI option if it exists, if not, use the default stage (which lives in provider.stage). So during development you can safely deploy with serverless deploy, but during production you can do serverless deploy --stage production and the stage will be picked up for you without having to make any changes to serverless.yml.</p><p>You can have as many variable references as you want, from any source you want, and each of them can be of different type and different name.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#using-custom-variable-syntax">#</a>Using Custom Variable Syntax</h3><p>In some cases, the ${xxx} variable syntax conflicts with some CloudFormation functionality. In that case you can provide a custom syntax to overwrite our default ${xxx} syntax by setting the provider.variableSyntax property to the desired regex:</p><pre>service: new-service provider:  name: aws  runtime: nodejs6.10  variableSyntax: &quot;\\${{([ ~:a-zA-Z0-9._\\&#39;\&quot;,\\-\\/\\(\\)]+?)}}&quot; custom:  myStage: ${{opt:stage}}</pre><p>In this example, we’re overwriting the default regex for our variable syntax. So whenever you define variables, you now need to use ${{}} instead of ${} (double curly brackets).</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#migrating-serverlessenvyml">#</a>Migrating serverless.env.yml</h3><p>Previously we used the serverless.env.yml file to track Serverless Variables. It was a completely different system with different concepts. To migrate your variables from serverless.env.yml, you&#39;ll need to decide where you want to store your variables.</p><p><strong>Using a config file:</strong> You can still use serverless.env.yml, but the difference now is that you can structure the file however you want, and you&#39;ll need to reference each variable/property correctly in serverless.yml. For more info, you can check the file reference section above.</p><p><strong>Using the same </strong><strong>serverless.yml file:</strong> You can store your variables in serverless.yml if they don&#39;t contain sensitive data, and then reference them elsewhere in the file using self:someProperty. For more info, you can check the self reference section above.</p><p><strong>Using environment variables:</strong> You can instead store your variables in environment variables and reference them with env.someEnvVar. For more info, you can check the environment variable reference section above.</p><p><strong>Making your variables stage/region specific:</strong> serverless.env.yml allowed you to have different values for the same variable based on the stage/region you&#39;re deploying to. You can achieve the same result by using the nesting functionality of the new variable system. For example, if you have two different ARNs, one for dev stage and the other for prod stage, you can do the following: ${env:${opt:stage}_arn}. This will make sure the correct env var is referenced based on the stage provided as an option. Of course you&#39;ll need to export both dev_arn and prod_arn env vars on your local system.</p><p>Now you don’t need serverless.env.yml at all, but you can still use it if you want. It&#39;s just not required anymore. Migrating to the new variable system is easy and you just need to know how the new system works and make small adjustments to how you store &amp; reference your variables.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/#pseudo-parameters-reference">#</a>Pseudo Parameters Reference</h3><p>You can reference <a href="http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html">AWS Pseudo Parameters</a></p><p>Here’s an example:</p><pre>Resources:  - &#39;Fn::Join&#39;:  - &#39;:&#39;  -  - &#39;arn:aws:logs&#39;  - Ref: &#39;AWS::Region&#39;  - Ref: &#39;AWS::AccountId&#39;  - &#39;log-group:/aws/lambda/*:*:*&#39;</pre><p><em>Originally published at </em><a href="https://serverless.com/framework/docs/providers/aws/guide/variables/"><em>serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0a7af76e840" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developerworld/serverless-variables-e0a7af76e840">Serverless Variables</a> was originally published in <a href="https://medium.com/developerworld">Developerworld</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Lambda Guide — Testing]]></title>
            <link>https://medium.com/developerworld/aws-lambda-guide-testing-41c877a92cd8?source=rss-4045737d1d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/41c877a92cd8</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Developer world]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 11:05:04 GMT</pubDate>
            <atom:updated>2018-07-06T11:05:04.806Z</atom:updated>
            <content:encoded><![CDATA[<p>While the Serverless Architecture introduces a lot of simplicity when it comes to serving business logic, some of its characteristics present challenges for testing. They are:</p><ul><li>The Serverless Architecture is an integration of separate, distributed services, which must be tested both independently, and together.</li><li>The Serverless Architecture is dependent on internet/cloud services, which are hard to emulate locally.</li><li>The Serverless Architecture can feature event-driven, asynchronous workflows, which are hard to emulate entirely.</li></ul><p>To get through these challenges, and to keep the <a href="http://martinfowler.com/bliki/TestPyramid.html">test pyramid</a> in mind, keep the following principles in mind:</p><ul><li>Write your business logic so that it is separate from your FaaS provider (e.g., AWS Lambda), to keep it provider-independent, reusable and more easily testable.</li><li>When your business logic is written separately from the FaaS provider, you can write traditional Unit Tests to ensure it is working properly.</li><li>Write Integration Tests to verify integrations with other services are working correctly.</li></ul><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/testing/#a-poor-example">#</a>A Poor Example</h3><p>Here is an example in Node.js of how to follow the practices above. The job this Function should perform is to save a user in a database and then send a welcome email:</p><pre>const db = require(&#39;db&#39;).connect(); const mailer = require(&#39;mailer&#39;); module.exports.saveUser = (event, context, callback) =&gt; { const user = { email: event.email, created_at: Date.now() } db.saveUser(user, function (err) { if (err) { callback(err); } else { mailer.sendWelcomeEmail(event.email); callback(); } }); };</pre><p>There are two main problems with this function:</p><ul><li>The business logic is not separate from the FaaS Provider. It’s bounded to how AWS Lambda passes incoming data (Lambda’s event object).</li><li>Testing this function will rely on separate services. Specifically, running a database instance and a mail server.</li></ul><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/testing/#writing-testable-aws-lambda-functions">#</a>Writing Testable AWS Lambda Functions</h3><p>Let’s refactor the above example to separate the business logic from the FaaS Provider.</p><pre>class Users { constructor(db, mailer) { this.db = db; this.mailer = mailer; } save(email, callback) { const user = { email: email, created_at: Date.now() } this.db.saveUser(user, function (err) { if (err) { callback(err); } else { this.mailer.sendWelcomeEmail(email); callback(); } }); } } module.exports = Users;</pre><pre>const db = require(&#39;db&#39;).connect(); const mailer = require(&#39;mailer&#39;); const Users = require(&#39;users&#39;); let users = new Users(db, mailer); module.exports.saveUser = (event, context, callback) =&gt; { users.save(event.email, callback); };</pre><p>Now, the above class keeps business logic separate. Further, the code responsible for setting up dependencies, injecting them, calling business logic functions and interacting with AWS Lambda is in its own file, which will be changed less often. This way, the business logic is not provider dependent, easier to re-use, and easier to test.</p><p>Further, this code doesn’t require running any external services. Instead of a real db and mailer services, we can pass mocks and assert if saveUser and sendWelcomeEmail has been called with proper arguments.</p><p>Unit Tests can easily be written to cover the above class. An integration test can be added by invoking the function (serverless invoke) with fixture email address, check if user is actually saved to DB and check if email was received to see if everything is working together.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/testing/#other">#</a>Other</h3><p>Here are a few links to services which can help you test locally:</p><ul><li><a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html">dynamodb-local</a></li><li><a href="https://github.com/mhart/kinesalite">kinesalite</a></li></ul><p><em>Originally published at </em><a href="https://serverless.com/framework/docs/providers/aws/guide/testing/"><em>serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41c877a92cd8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developerworld/aws-lambda-guide-testing-41c877a92cd8">AWS Lambda Guide — Testing</a> was originally published in <a href="https://medium.com/developerworld">Developerworld</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Lambda Guide — Deploying]]></title>
            <link>https://medium.com/developerworld/aws-lambda-guide-deploying-ad99b68b4f28?source=rss-4045737d1d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad99b68b4f28</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Developer world]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 11:02:02 GMT</pubDate>
            <atom:updated>2018-07-06T11:02:53.961Z</atom:updated>
            <content:encoded><![CDATA[<p>The Serverless Framework was designed to provision your AWS Lambda Functions, Events and infrastructure Resources safely and quickly. It does this via a couple of methods designed for different types of deployments.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/deploying/#deploy-all">#</a>Deploy All</h3><p>This is the main method for doing deployments with the Serverless Framework:</p><pre>serverless deploy</pre><p>Use this method when you have updated your Function, Event or Resource configuration in serverless.yml and you want to deploy that change (or multiple changes at the same time) to Amazon Web Services.</p><p><strong>Note:</strong> You can always enforce a deployment using the --force option.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/deploying/#how-it-works">#</a>How It Works</h3><p>The Serverless Framework translates all syntax in serverless.yml to a single AWS CloudFormation template. By depending on CloudFormation for deployments, users of the Serverless Framework get the safety and reliability of CloudFormation.</p><ul><li>An AWS CloudFormation template is created from your serverless.yml.</li><li>If a Stack has not yet been created, then it is created with no resources except for an S3 Bucket, which will store zip files of your Function code.</li><li>The code of your Functions is then packaged into zip files.</li><li>Serverless fetches the hashes for all files of the previous deployment (if any) and compares them against the hashes of the local files.</li><li>Serverless terminates the deployment process if all file hashes are the same.</li><li>Zip files of your Functions’ code are uploaded to your Code S3 Bucket.</li><li>Any IAM Roles, Functions, Events and Resources are added to the AWS CloudFormation template.</li><li>The CloudFormation Stack is updated with the new CloudFormation template.</li><li>Each deployment publishes a new version for each function in your service.</li></ul><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/deploying/#tips">#</a>Tips</h3><ul><li>Use this in your CI/CD systems, as it is the safest method of deployment.</li><li>You can print the progress during the deployment if you use verbose mode, like this:</li><li>serverless deploy --verbose</li><li>This method uses the AWS CloudFormation Stack Update method. CloudFormation is slow, so this method is slower. If you want to develop more quickly, use the serverless deploy function command (described below)</li><li>This method defaults to dev stage and us-east-1 region. You can change the default stage and region in your serverless.yml file by setting the stage and region properties inside a provider object as the following example shows:</li><li>service: service-name provider: name: aws stage: beta region: us-west-2</li><li>You can also deploy to different stages and regions by passing in flags to the command:</li><li>serverless deploy --stage production --region eu-central-1</li><li>You can specify your own S3 bucket which should be used to store all the deployment artifacts. The deploymentBucket config which is nested under provider lets you e.g. set the name or the serverSideEncryption method for this bucket</li><li>You can make uploading to S3 faster by adding --aws-s3-accelerate</li></ul><p>Check out the <a href="https://serverless.com/framework/docs/providers/aws/cli-reference/deploy">deploy command docs</a> for all details and options.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/deploying/#deploy-function">#</a>Deploy Function</h3><p>This deployment method does not touch your AWS CloudFormation Stack. Instead, it simply overwrites the zip file of the current function on AWS. This method is much faster, since it does not rely on CloudFormation.</p><pre>serverless deploy function --function myFunction</pre><p><strong>-Note:</strong> You can always enforce a deployment using the --force option. -<strong>Note:</strong> You can use --update-config to change only Lambda configuration without deploying code.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/deploying/#how-it-works-1">#</a>How It Works</h3><ul><li>The Framework packages up the targeted AWS Lambda Function into a zip file.</li><li>The Framework fetches the hash of the already uploaded function .zip file and compares it to the local .zip file hash.</li><li>The Framework terminates if both hashes are the same.</li><li>That zip file is uploaded to your S3 bucket using the same name as the previous function, which the CloudFormation stack is pointing to.</li></ul><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/deploying/#tips-1">#</a>Tips</h3><ul><li>Use this when you are developing and want to test on AWS because it’s much faster.</li><li>During development, people will often run this command several times, as opposed to serverless deploy which is only run when larger infrastructure provisioning is required.</li></ul><p>Check out the <a href="https://serverless.com/framework/docs/providers/aws/cli-reference/deploy">deploy command docs</a> for all details and options.</p><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/deploying/#deploying-a-package">#</a>Deploying a package</h3><p>This deployment option takes a deployment directory that has already been created with serverless package and deploys it to the cloud provider. This allows you to easier integrate CI / CD workflows with the Serverless Framework.</p><pre>serverless deploy --package path-to-package</pre><h3><a href="https://serverless.com/framework/docs/providers/aws/guide/deploying/#how-it-works-2">#</a>How It Works</h3><ul><li>The argument to the --package flag is a directory that has been previously packaged by Serverless (with serverless package).</li><li>The deploy process bypasses the package step and uses the existing package to deploy and update CloudFormation stacks.</li></ul><p><em>Originally published at </em><a href="https://serverless.com/framework/docs/providers/aws/guide/deploying/"><em>serverless.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad99b68b4f28" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developerworld/aws-lambda-guide-deploying-ad99b68b4f28">AWS Lambda Guide — Deploying</a> was originally published in <a href="https://medium.com/developerworld">Developerworld</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>