Giter Club home page Giter Club logo

Comments (7)

DLOKESHREDDY avatar DLOKESHREDDY commented on August 11, 2024 1

pip install --upgrade --no-cache awscli-local

Thanks alot ,I got resolved my issue by using the above querry.
Thanks@david93111

from awscli-local.

gregsdennis avatar gregsdennis commented on August 11, 2024

I noticed that aws also installs a .cmd file. This is just a batch file that subsequently runs the awslocal script.

The install for awslocal should also install such a file.

from awscli-local.

gregsdennis avatar gregsdennis commented on August 11, 2024

Workaround @fullstack74

Create a .cmd file with the following contents:

REM    env_dict['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', '_not_needed_locally_')
REM    env_dict['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', '_not_needed_locally_')

SET AWS_ACCESS_KEY_ID=_not_needed_locally_
SET AWS_SECRET_ACCESS_KEY=_not_needed_locally_

aws.cmd %*

from awscli-local.

whummer avatar whummer commented on August 11, 2024

Thanks for reporting @fullstack74 @gregsdennis .

The install for awslocal should also install such a file.

Would any of you be able to provide such a .cmd file? Thanks!

from awscli-local.

david93111 avatar david93111 commented on August 11, 2024

Same error for Windows 10, definitely should add this cmd creation for Python.
Thanks a lot, @gregsdennis , for pointing out the aws.cmd file, that solve part of the issue but not every variable is accounted in your script so you have to configure your AWS CLI for default region and other stuff.

What i did was look what the AWS command line was doing, basicaly they have all the logic in an clidriver inside the site-packages that the aws for linux file and the aws.cmd share.

So, based on how awscli original script files do things, I create a new file that uses the same code for telling windows to execute the python code as a script and have to add to subprocess.Popen the shell=true flag in order to make it work when no arguments are given (the aws normal cli script manages the command missing part) and my awslocal.cmd file repeat all the logic in the original file , for me it's working properly (on Window 10, but should also work for 7) and basically the whole file looks like:

@echo OFF
REM="""
setlocal
set PythonExe=""
set PythonExeFlags=

for %%i in (cmd bat exe) do (
    for %%j in (python.%%i) do (
        call :SetPythonExe "%%~$PATH:j"
    )
)
for /f "tokens=2 delims==" %%i in ('assoc .py') do (
    for /f "tokens=2 delims==" %%j in ('ftype %%i') do (
        for /f "tokens=1" %%k in ("%%j") do (
            call :SetPythonExe %%k
        )
    )
)
%PythonExe% -x %PythonExeFlags% "%~f0" %*
exit /B %ERRORLEVEL%
goto :EOF

:SetPythonExe
if not ["%~1"]==[""] (
    if [%PythonExe%]==[""] (
        set PythonExe="%~1"
    )
)
goto :EOF
"""

# ===================================================
# Python script starts here
# ===================================================

import os
import sys
import subprocess
import six
from threading import Thread

PARENT_FOLDER = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
if os.path.isdir(os.path.join(PARENT_FOLDER, '.venv')):
    sys.path.insert(0, PARENT_FOLDER)

from localstack_client import config


def get_service():
    for param in sys.argv[1:]:
        if not param.startswith('-'):
            return param


def get_service_endpoint():
    service = get_service()
    if service == 's3api':
        service = 's3'
    return config.get_service_endpoints().get(service)


def usage():
    print(__doc__.strip())


def to_str(s):
    if six.PY3 and not isinstance(s, six.string_types):
        s = s.decode('utf-8')
    return s


def run(cmd, env={}):

    def output_reader(pipe, out):
        with pipe:
            for line in iter(pipe.readline, b''):
                line = to_str(line)
                out.write(line)
                out.flush()

    process = subprocess.Popen(cmd, stderr=subprocess.PIPE,
        stdout=subprocess.PIPE, stdin=subprocess.PIPE, env=env, shell=True)

    Thread(target=output_reader, args=[process.stdout, sys.stdout]).start()
    Thread(target=output_reader, args=[process.stderr, sys.stderr]).start()

    process.wait()
    sys.exit(process.returncode)


def main():
    if len(sys.argv) > 1 and sys.argv[1] == '-h':
        return usage()

    # get service and endpoint
    endpoint = get_service_endpoint()
    service = get_service()
    if not endpoint and service:
        print('ERROR: Unable to find LocalStack endpoint for service "%s"' % service)
        return sys.exit(1)

    # prepare cmd args
    cmd_args = list(sys.argv)
    cmd_args[0] = 'aws'
    if endpoint:
        cmd_args.insert(1, '--endpoint-url=%s' % endpoint)
        if 'https' in endpoint:
            cmd_args.insert(2, '--no-verify-ssl')

    # prepare env vars
    env_dict = os.environ.copy()
    env_dict['PYTHONWARNINGS'] = 'ignore:Unverified HTTPS request'
    env_dict['AWS_DEFAULT_REGION'] = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')
    env_dict['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', '_not_needed_locally_')
    env_dict['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', '_not_needed_locally_')

    # run the command
    run(cmd_args, env_dict)

if __name__ == '__main__':
    sys.exit(main())

@whummer i don't know if this is the best soultion, or there are others better, i'm not a python expert , but if you think this can work easily you can centralize the logic of this script in other file that both your linux command file and this cmd file share when executed and should work very similar to the original awscli script.

from awscli-local.

gregsdennis avatar gregsdennis commented on August 11, 2024

@david93111 thanks for putting that together. My script was obviously suited to my direct needs, and just to get it working.

from awscli-local.

whummer avatar whummer commented on August 11, 2024

Thanks for reporting @gregsdennis @david93111 . This should be fixed in 8878701 . Can you please give it a try with the latest version 0.5 of the pip package (pip install --upgrade --no-cache awscli-local)? Please report here if the problem persists. Thanks

from awscli-local.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.