Skip to content
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

deploy_frontend.sh grep command fails on mac #5940

Closed
Srokit opened this issue Sep 13, 2023 · 7 comments · Fixed by aws/aws-sam-cli-app-templates#458
Closed

deploy_frontend.sh grep command fails on mac #5940

Srokit opened this issue Sep 13, 2023 · 7 comments · Fixed by aws/aws-sam-cli-app-templates#458
Labels
area/init sam init contributors/good-first-issue Good first issue for a contributor contributors/welcome Contributors are welcome to work on this

Comments

@Srokit
Copy link

Srokit commented Sep 13, 2023

Description

sam init command creates a 'deploy_frontend.sh' script which will fail for MacOS's default grep command. This is a commonly used OS and grep version for developers. The mac grep command does not support the -P flag, but the generated script calls

invalidation_id=$(echo "$invalidation_output" | grep -oP '(?<="Id": ")[^"]+')

on line 41

that grep -oP part fails because the P option is not recognized.

I am sure there is another regex tool that we can use to extract that id string out of the invalidation_output (I have not come up with a solution myself yet).

The script will end up not waiting for the cloudfront invalidation-completed signal and will just end early. Not super breaking, but not ideal.

The solution I put in myself is not elegant and simply allows the error to happen and then calls ggrep instead which can be installed by homebrew on mac and has the -P option.

Steps to reproduce

On MacOS

Run

$ sam init

Select Option 1, then 13, then N, then N, then enter a name

Then

$ ./deploy_frontend.sh

See output

Observed result

usage: grep [-abcdDEFGHhIiJLlMmnOopqRSsUVvwXxZz] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]

usage: aws [options] [ ...] [parameters]
To see help text, you can run:

aws help
aws help
aws help

aws: error: argument --id: expected one argument

The invalidation is now complete - please visit your cloudfront URL to test

Expected result

Expected no errors

Additional environment details

  1. OS: Mac OS Monterey 12.6.2 (21G320) (M1 Silicon)
  2. If using the SAM CLI, sam --version: SAM CLI, version 1.97.0
  3. AWS region: us-west-1
@Srokit Srokit added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Sep 13, 2023
@xazhao
Copy link
Contributor

xazhao commented Sep 15, 2023

Transfer the issue to sam cli.

@xazhao xazhao transferred this issue from aws/serverless-application-model Sep 15, 2023
@sriram-mv sriram-mv added area/init sam init stage/needs-investigation Requires a deeper investigation and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Sep 15, 2023
@mrichman
Copy link

If you install jq you can do this: invalidation_id=$(echo $invalidation_output | jq -r '.Invalidation.Id')

@Srokit
Copy link
Author

Srokit commented Sep 29, 2023

If you install jq you can do this: invalidation_id=$(echo $invalidation_output | jq -r '.Invalidation.Id')

You should add a PR for this and reference this issue :D

@Srokit
Copy link
Author

Srokit commented Sep 29, 2023

Actually I'll make a PR. shouldn't be too tricky.

@Srokit
Copy link
Author

Srokit commented Sep 29, 2023

@mrichman The jq command is not out of the box with Mac. Just tried it. I think we should have an out of the box solution.

@sriram-mv sriram-mv added contributors/welcome Contributors are welcome to work on this contributors/good-first-issue Good first issue for a contributor and removed stage/needs-investigation Requires a deeper investigation labels Oct 5, 2023
cibinmathew added a commit to cibinmathew/aws-sam-cli-app-templates that referenced this issue Oct 21, 2023
Fixes: aws/aws-sam-cli#5940
Script was failing for MacOS's default grep command
cibinmathew added a commit to cibinmathew/aws-sam-cli-app-templates that referenced this issue Oct 21, 2023
Fixes: aws/aws-sam-cli#5940
Script was failing for MacOS's default grep command
cibinmathew added a commit to cibinmathew/aws-sam-cli-app-templates that referenced this issue Oct 21, 2023
Fixes: aws/aws-sam-cli#5940
Script was failing for MacOS's default grep command
@justinmk3
Copy link

Proposed fix: aws/aws-sam-cli-app-templates#458

github-merge-queue bot pushed a commit to aws/aws-sam-cli-app-templates that referenced this issue Nov 7, 2023
Fixes: aws/aws-sam-cli#5940
Script was failing for MacOS's default grep command

Co-authored-by: Mohamed Elasmar <[email protected]>
Copy link
Contributor

github-actions bot commented Nov 7, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

SmartBigGuru added a commit to SmartBigGuru/aws-sam-cli-app-templates that referenced this issue Nov 17, 2023
Fixes: aws/aws-sam-cli#5940
Script was failing for MacOS's default grep command

Co-authored-by: Mohamed Elasmar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/init sam init contributors/good-first-issue Good first issue for a contributor contributors/welcome Contributors are welcome to work on this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants