Deploy with Visual Studio 2017 fails #93. Genifycom opened this Issue Apr 2, 2017 10 comments Comments. Assignees No one assigned Labels guidance. Projects None yet Milestone No milestone 8 participants Copy link. [aws/aws-lambda-dotnet#93] Generated using Yeoman. Using the AWS SDK in Visual Studio 2017, we created the Widgets.Lambda project using the AWS Lambda Web API template. Since our APIs will be connecting into DynamoDB, we needed to add the following to the startup.cs file.
![]()
You can build a serverless Lambda application by using an AWS Toolkit for Visual Studio template. The Lambda project templates include one for an AWS Serverless Application, which is the AWS Toolkit for Visual Studio implementation of the AWS Serverless Application Model (AWS SAM). Using this project type you can develop a collection of AWS Lambda functions and deploy them with any necessary AWS resources as a whole application, using AWS CloudFormation to orchestrate the deployment.
For prerequisites and information about setting up the AWS Toolkit for Visual Studio, see Using the AWS Lambda Templates in the AWS Toolkit for Visual Studio.
Topics
Create a New AWS Serverless Application Project
Examine the Files in the Serverless Application
Blog.cs
Blog.cs is a simple class used to represent the blog items that are stored in Amazon DynamoDB.
Functions.cs
Functions.cs defines the C# functions to expose as Lambda functions. There are four functions defined to manage a blog platform:
Each of these functions accepts an APIGatewayProxyRequest object and returns an APIGatewayProxyResponse.
You expose these Lambda functions as HTTP APIs by using Amazon API Gateway. The
APIGatewayProxyRequest contains all the information representing the HTTP request. The GetBlogAsync task finds the blog ID in the resource path or query string.
The default constructor for this class passes the name of the DynamoDB table storing the blogs as an environment variable. This environment variable is set when Lambda deploys the function.
serverless.template
The
serverless.template is the AWS CloudFormation template used to deploy the four functions. The parameters for the template enable you to set the name of the DynamoDB table, and choose whether you want DynamoDB to create the table or to assume the table is already created.
The template defines four resources of type
AWS::Serverless::Function . This is a special meta resource defined as part of the AWS SAM specification. The specification is a transform that is applied to the template as part of the DynamoDB deployment. The transform expands the meta resource type into the more concrete resources, like AWS::Lambda::Function and AWS::IAM::Role . The transform is declared at the top of the template file, as follows.
The
GetBlogs declaration is similar to the function declarations.
Many of the fields are similar to those of a Lambda project deployment. In the
Environment property, the name of the DynamoDB table is passed in as an environment variable. The CodeUri property tells DynamoDB where your application bundle is stored in Amazon S3. Leave this property blank. The toolkit fills it in during deployment, after it uploads the application bundle to S3 (it won't change the template file on disk when it does so). The Events section is where the HTTP bindings are defined for your Lambda function. This is all the API Gateway setup you need for your function. You can also set up other types of event sources in this section.
With shadow copies, changes to a file are saved as a new file, so the original is still recoverable. That accesses Windows' shadow copies. It's turned off by default, but who knows - you may have gotten lucky and some program you installed turned it on. Recover overwritten excel file windows 10. Right-click the file, open its properties, and click on the Previous Versions tab. You've got one realistic chance.
One of the benefits of using AWS CloudFormation to manage the deployment is you can also add and configure any other AWS resources necessary for your application in the template, and let DynamoDB take care of creating and deleting the resources.
Deploy the Serverless Application
Deploy the serverless application by right-clicking the project and choosing Publish to AWS Lambda.
This launches the deployment wizard, and because all the Lambda configuration was done in the
serverless.template file, all you need to supply are the following:
These must exist in the same AWS Region.
Because the serverless template has parameters, an additional page is displayed in the wizard so you can specify the values for the parameters. You can leave the
BlogTableName property blank and let CloudFormation generate a unique name for the table. You do need to set ShouldCreateTable to true so that DynamoDB will create the table. To use an existing table, enter the table name and set the ShouldCreateTable parameter to false . You can leave the other fields at their default values and choose Publish.
![]()
Once the publish step is complete, the CloudFormation stack view is displayed in AWS Explorer. This view shows the progress of the creation of all the resources declared in your serverless template.
Test the Serverless Application
When the stack creation is complete, the root URL for the API Gateway is displayed on the page. If you click that link, it returns an empty JSON array because you haven't added any blogs to the table. To get blogs in the table, you need to make an HTTP PUT method to this URL, passing in a JSON document that represents the blog. You can do that in code or in any number of tools. This example uses the Postman tool, which is a Chrome browser extension, but you can use any tool you like. In this tool, you set the URL and change the method to PUT. In the Body tab, you put in some sample content. When you make the HTTP call, you can see the blog ID is returned.
Go back to the browser with the link to the AWS Serverless URL and you can see you are getting back the blog you just posted.
Using the AWS Serverless Application template, you can manage a collection of Lambda functions and the application's other AWS resources. Also, with the AWS SAM specification, you can use a simplified syntax to declare a serverless application in the DynamoDB template.
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |