-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Added tutorial topic #1047
Conversation
Adds a `pkglint` rule to enforce presence of the `*.snk` pattern in both the `.gitignore` and `.npmignore` file as a way to make it harder for one to accidentially push the material to public locations. This was missed in #643.
docs/src/tutorial.rst
Outdated
exports.main = function(event, context, callback) { | ||
if (event.httpMethod != null) { | ||
if (event.httpMethod != "") { | ||
if (event.httpMethod == "GET") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These three lines below each other make me restless. There should be a better way to express this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've refactored the code to use a try block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how that helps.
What's making me nervous here, and I should have been more clear, is you're doing the following:
if (variable unequal to one thing)
AND
if (variable unequal to other thing)
AND
if (variable IS EUQAL to something else)
THEN do something
Well first of all, if event.httpMethod == "GET"
, then of course it must be != null
and != ""
, so there's no need to check those. You could have gotten away with writing:
if (event.httpMethod == "GET") {
// ...
}
if (event.httpMethod == "POST") {
// ...
}
// etc
And have the same effect.
The only reason you would type it this way, is because maybe at the end you might write an else
, something like this:
if (event.httpMethod != "") {
if (Event.httpMethod == "GET") {
// lots of
}
// ...lines here...
} else {
// Do something special
}
However, because the inner block is SO LONG, I have a hard time visually scanning whether that's true or not. So I recommend you invert the condition into an early abort, if that's the case:
if (event.httpMethod == "") {
// Do something special
return;
}
if (event.httpMethod == "GET") {
/// ...
}
if (event.httpMethod == "POST") {
// ...
}
// etc
Long blocks and redundant ifs make me nervous because they might be hiding logic that's easy to miss, and so I recommend that you change the code layout to be very clear and straightforward about what's happening.
I'm not sure how adding a try
helps there. But also, I can't find the code back in the PR after it has exploded through the merge, so I'll have a look again after it has normalized.
Also
Forgot to take note of this first time around, but since you're doing JavaScript, REPLACE ALL INSTANCES of the following:
==
=>===
!=
=>!==
The 2-character variants are not to be trusted.
docs/src/tutorial.rst
Outdated
The next step is to create a |LAM| function to list all of the widgets in our | ||
|S3| bucket. | ||
|
||
Create the directory *resource* at the same level as the *bin* directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resource or resources?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also is that the best name for this directory?
docs/src/tutorial.rst
Outdated
exports.main = function(event, context, callback) { | ||
if (event.httpMethod == "GET") { | ||
if (event.path.length == 1) { | ||
S3.listObjectsV2({ Bucket: bucketName }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use NodeJS8 and you can rewrite this to be async
, which is way more readable:
exports.main = async function(event, context) {
try {
if (event.httpMethod == "GET") {
if (event.path.length == 1) {
const data = await S3.listObjectsV2({ Bucket: bucketName }).promise();
var body = { widgets: data.Contents.map(function(e) { return e.Key }) };
return {
statusCode: 200,
headers: {},
body: JSON.stringify(body)
};
}
}
} catch(error) {
var body = error.stack || JSON.stringify(error, null, 2);
var response = makeError(body);
return response;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way where does makeError
come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I no longer use helper functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not the point. I like helper functions. I just didn't see it defined. Or did I miss it?
docs/src/tutorial.rst
Outdated
|
||
npm install @aws-cdk/aws-apigateway | ||
npm install @aws-cdk/aws-lambda | ||
npm install @aws-cdk/aws-s3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably all possible on one line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
.. code-block:: sh | ||
|
||
npm run build | ||
cdk synth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to reinforce that when you make changes you should rebuild and see if they are what you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough
Encountered someone at a workshop who had copy/pasted into the wrong file, replacing their app instantiation and invocation, and the error message was "could not find cdk.out" Which was super unhelpful and took me a good while to figure out what had happened. Pinpoint at least one possible cause of this happening in the error message.
) Adds an option to specify `partitionKey` and/or `sortKey` when the table is initialized. This is identical to calling `addPartitionKey` and `addSortKey`. Fixes #1051
…-cdk into dougsch/new-tutorial
* feat(aws-sqs): improvements to IAM grants API Moved `grantXxx` methods from `Queue` to `QueueRef`, so they can now be performed on imported queues. Added commonly needed permissions to `grantConsumeMessages` and `grantSendMessages` such as `sqs:GetQueueAttributes`, `sqs:GetQueueUrl` and the various `sqs:xxxBatch` actions. Added support for adding arbitrary actions to each of the grant methods. Exposed `queue.grant(...actions)` as a general purpose grant method which allows users to customize the set of actions for this specific resource/principal pair. BREAKING CHANGE: `queue.grantReceiveMessages` has been removed. It is unlikely that this would be sufficient to interact with a queue. Alternatively you can use `queue.grantConsumeMessages` or `queue.grant('sqs:ReceiveMessage')` if there's a need to only grant this action.
Something went a little weird with your merge. |
Adds a uniform high-level API for AWS Lambda event sources. This API allows developers to use a single API `lambda.addEventSource(source)` to connect a function with any type of event source. The `IEventSource` class is defined in the aws-lambda module and the aws-lambda-event-sources module includes implementations for various event sources. Each implementation utilizes the relevant mechanism. Currently supported: - SQS - SNS - S3 We eventually want to support all event sources as described in the Lambda developer guide.
This change implements two asset bandwidth conservation measures: - If a lambda.AssetCode object is reused for multiple Lambdas, the same underyling Asset object will be reused (which leads to the asset data only being uploaded once). - If nonetheless multiple Asset objects are created for the same source data, the data will only be uploaded once and subsequently copied on the server-side to avoid the additional data transfer. Fixes #989.
…-cdk into dougsch/new-tutorial
WTF is going on? When I had my dougsch/new-tutorial branch checked out, I ran "git diff --name-only master" and it gave me index.rst and tutorial.rst. Now it says I have 191 file diffs? OK, I just rebased my branch against master: git checkout master Got a merge conflict in tutorial.rst. How could that happen as master does not have a tutorial.rst???? git pull Gave me: On branch dougsch/new-tutorial nothing to commit, working tree clean git diff --name-only master Gave me: docs/src/index.rst What else am I supposed to do??? |
Forget this. I'm trying a new branch, dougsch/tutorial, and new PR. |
Doug, I think the problem is in your rebasing. Don't rebase!Rebasing will try to move the commits around, change their identity, resurface merge conflicts that you've already solved, etc. Rebasing is a good solution if you're committing directly to master and you want to keep your history clean. However, we work via PRs that we squash, so there's no need to keep the history clean. Any change goes into master as a single commit, and the history leading up to that commit is lost. Your life is going to be a lot better if you stick to the following:
If you don't yet have a script installed yet that shows your current branch in your shell prompt, get one today. Super handy! |
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.
Resolves comments from PR #872; Steve's review.