aws lambda create-function: UnicodeDecodeError: 'ascii' codec can't decode byte 0x91 in position 12: ordinal not in range(128)
I'm trying to use the awscli to create a Lambda function. aws lambda create-function is failing with a UnicodeDecodeError: 'ascii' codec can't decode byte 0x91 in position 12: ordinal not in range(128)
Here's a scrubbed version of the output with --debug enabled:
$ ./deploy.sh
+ exec_role=LambdaKinesisS3Archive
+ exec_role_arn=arn:aws:iam::XXXXXXXXXXXX:role/LambdaKinesisS3Archive
+ src_js=ProcessKinesisRecords.js
++ basename ProcessKinesisRecords.js .js
+ src_zip=ProcessKinesisRecords.zip
++ dirname ./deploy.sh
++ dirname ./deploy.sh
+ zip ./ProcessKinesisRecords.zip ./ProcessKinesisRecords.js
updating: ProcessKinesisRecords.js (deflated 40%)
++ dirname ./deploy.sh
+ aws lambda create-function --debug --function-name ProcessKinesisRecords --zip-file file://./ProcessKinesisRecords.zip --role arn:aws:iam::XXXXXXXXXXXX:role/LambdaKinesisS3Archive --handler ProcessKinesisRecords.handler --runtime nodejs
2015-04-23 11:35:27,379 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/1.7.23 Python/2.7.6 Darwin/14.1.1, botocore version: 0.104.0
2015-04-23 11:35:27,379 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['lambda', 'create-function', '--debug', '--function-name', 'ProcessKinesisRecords', '--zip-file', 'file://./ProcessKinesisRecords.zip', '--role', 'arn:aws:iam::XXXXXXXXXXXX:role/LambdaKinesisS3Archive', '--handler', 'ProcessKinesisRecords.handler', '--runtime', 'nodejs']
2015-04-23 11:35:27,379 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_scalar_parsers at 0x10e3f1320>
2015-04-23 11:35:27,379 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_assume_role_provider at 0x10e3a7578>
2015-04-23 11:35:27,385 - MainThread - botocore.hooks - DEBUG - Event service-data-loaded.lambda: calling handler <function register_retries_for_service at 0x10e05ede8>
2015-04-23 11:35:27,387 - MainThread - botocore.handlers - DEBUG - Registering retry handlers for service: lambda
2015-04-23 11:35:27,388 - MainThread - botocore.hooks - DEBUG - Event building-command-table.lambda: calling handler <function add_waiters at 0x10e3b5aa0>
2015-04-23 11:35:27,389 - MainThread - awscli.clidriver - DEBUG - OrderedDict([(u'function-name', <awscli.arguments.CLIArgument object at 0x10e758910>), (u'runtime', <awscli.arguments.CLIArgument object at 0x10e758950>), (u'role', <awscli.arguments.CLIArgument object at 0x10e758990>), (u'handler', <awscli.arguments.CLIArgument object at 0x10e7589d0>), (u'description', <awscli.arguments.CLIArgument object at 0x10e758a10>), (u'timeout', <awscli.arguments.CLIArgument object at 0x10e758a50>), (u'memory-size', <awscli.arguments.CLIArgument object at 0x10e758a90>), (u'code', <awscli.arguments.CLIArgument object at 0x10e758ad0>)])
2015-04-23 11:35:27,389 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.lambda.create-function: calling handler <function add_streaming_output_arg at 0x10e2a47d0>
2015-04-23 11:35:27,389 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.lambda.create-function: calling handler <function _flatten_code_argument at 0x10e3f90c8>
2015-04-23 11:35:27,389 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.lambda.create-function: calling handler <function add_cli_input_json at 0x10e3a1d70>
2015-04-23 11:35:27,390 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.lambda.create-function: calling handler <function unify_paging_params at 0x10e2b0b18>
2015-04-23 11:35:27,390 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.lambda.create-function: calling handler <function add_generate_skeleton at 0x10e3a70c8>
2015-04-23 11:35:27,390 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.lambda.create-function: calling handler <bound method CliInputJSONArgument.override_required_args of <awscli.customizations.cliinputjson.CliInputJSONArgument object at 0x10e758b90>>
2015-04-23 11:35:27,390 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.lambda.create-function: calling handler <bound method GenerateCliSkeletonArgument.override_required_args of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x10e758d50>>
2015-04-23 11:35:27,391 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.lambda.create-function.function-name: calling handler <function uri_param at 0x10e2925f0>
2015-04-23 11:35:27,392 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.lambda.create-function: calling handler <awscli.argprocess.ParamShorthand object at 0x10e3f6210>
2015-04-23 11:35:27,392 - MainThread - awscli.argprocess - DEBUG - Detected structure: scalar
2015-04-23 11:35:27,392 - MainThread - awscli.arguments - DEBUG - Unpacked value of u'ProcessKinesisRecords' for parameter "function_name": u'ProcessKinesisRecords'
2015-04-23 11:35:27,392 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.lambda.create-function.runtime: calling handler <function uri_param at 0x10e2925f0>
2015-04-23 11:35:27,392 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.lambda.create-function: calling handler <awscli.argprocess.ParamShorthand object at 0x10e3f6210>
2015-04-23 11:35:27,392 - MainThread - awscli.argprocess - DEBUG - Detected structure: scalar
2015-04-23 11:35:27,392 - MainThread - awscli.arguments - DEBUG - Unpacked value of u'nodejs' for parameter "runtime": u'nodejs'
2015-04-23 11:35:27,392 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.lambda.create-function.role: calling handler <function uri_param at 0x10e2925f0>
2015-04-23 11:35:27,392 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.lambda.create-function: calling handler <awscli.argprocess.ParamShorthand object at 0x10e3f6210>
2015-04-23 11:35:27,392 - MainThread - awscli.argprocess - DEBUG - Detected structure: scalar
2015-04-23 11:35:27,393 - MainThread - awscli.arguments - DEBUG - Unpacked value of u'arn:aws:iam::XXXXXXXXXXXX:role/LambdaKinesisS3Archive' for parameter "role": u'arn:aws:iam::XXXXXXXXXXXX:role/LambdaKinesisS3Archive'
2015-04-23 11:35:27,393 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.lambda.create-function.handler: calling handler <function uri_param at 0x10e2925f0>
2015-04-23 11:35:27,393 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.lambda.create-function: calling handler <awscli.argprocess.ParamShorthand object at 0x10e3f6210>
2015-04-23 11:35:27,393 - MainThread - awscli.argprocess - DEBUG - Detected structure: scalar
2015-04-23 11:35:27,393 - MainThread - awscli.arguments - DEBUG - Unpacked value of u'ProcessKinesisRecords.handler' for parameter "handler": u'ProcessKinesisRecords.handler'
2015-04-23 11:35:27,393 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.lambda.create-function.description: calling handler <function uri_param at 0x10e2925f0>
2015-04-23 11:35:27,393 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.lambda.create-function.timeout: calling handler <function uri_param at 0x10e2925f0>
2015-04-23 11:35:27,393 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.lambda.create-function.memory-size: calling handler <function uri_param at 0x10e2925f0>
2015-04-23 11:35:27,393 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.lambda.create-function.zip-file: calling handler <function uri_param at 0x10e2925f0>
2015-04-23 11:35:27,394 - MainThread - awscli.clidriver - DEBUG - Exception caught in main()
Traceback (most recent call last):
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/awscli/clidriver.py", line 183, in main
return command_table[parsed_args.command](remaining, parsed_args)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/awscli/clidriver.py", line 369, in __call__
return command_table[parsed_args.operation](remaining, parsed_globals)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/awscli/clidriver.py", line 510, in __call__
self.arg_table)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/awscli/clidriver.py", line 564, in _build_call_parameters
value = self._unpack_arg(arg_object, value)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/awscli/clidriver.py", line 576, in _unpack_arg
cli_argument, value)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/awscli/argprocess.py", line 79, in unpack_argument
operation_name=operation_name)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/botocore/session.py", line 767, in emit_first_non_none_response
responses = self._events.emit(event_name, **kwargs)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/botocore/hooks.py", line 226, in emit
return self._emit(event_name, kwargs)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/botocore/hooks.py", line 209, in _emit
response = handler(**kwargs)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/awscli/argprocess.py", line 96, in uri_param
return _check_for_uri_param(cli_argument, value)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/awscli/argprocess.py", line 103, in _check_for_uri_param
return get_paramfile(value)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/awscli/paramfile.py", line 90, in get_paramfile
data = PrefixMap[prefix](prefix, path, **kwargs)
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/site-packages/awscli/paramfile.py", line 102, in get_file
return f.read()
File "/Users/roomkeyvince/.prmtbly/lib/python2.7/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0x91 in position 12: ordinal not in range(128)
2015-04-23 11:35:27,395 - MainThread - awscli.clidriver - DEBUG - Exiting with rc 255
'ascii' codec can't decode byte 0x91 in position 12: ordinal not in range(128)
aws lambda list-functions works correctly:
aws lambda list-functions
{
"Functions": [
{
"FunctionName": "s3-deploy-test",
"MemorySize": 128,
"CodeSize": 568,
"FunctionArn": "arn:aws:lambda:us-east-1:XXXXXXXXXXXX:function:s3-deploy-test",
"Handler": "index.handler",
"Role": "arn:aws:iam::XXXXXXXXXXXX:role/LambdaDeployer",
"Timeout": 30,
"LastModified": "2015-02-02T20:21:17.527+0000",
"Runtime": "nodejs",
"Description": "Auto-Deploy via S3"
}
]
}
The function listed above was created using the console.
I have awscli and it's dependencies installed in a virtualenv. Here are the module versions:
$ python --version
Python 2.7.6
$ pip freeze
alabaster==0.7.2
altgraph==0.10.2
awscli==1.7.23
Babel==1.3
backports.ssl-match-hostname==3.4.0.2
bcdoc==0.13.0
bdist-mpkg==0.5.0
bonjour-py==0.3
boto==2.38.0
botocore==0.104.0
certifi==14.5.14
cffi==0.9.2
colorama==0.3.3
cryptography==0.8
docutils==0.12
enum34==1.0.4
gnureadline==6.3.3
ipython==3.0.0
Jinja2==2.7.3
jmespath==0.6.2
jsonschema==2.4.0
macholib==1.5.1
MarkupSafe==0.23
matplotlib==1.3.1
mistune==0.5.1
modulegraph==0.10.4
ndg-httpsclient==0.3.3
nose==1.3.4
numpy==1.8.0rc1
numpydoc==0.5
pep8==1.6.2
ptyprocess==0.4
py2app==0.7.3
pyasn1==0.1.7
pycparser==2.10
Pygments==2.0.2
pyobjc-core==2.5.1
pyobjc-framework-Accounts==2.5.1
pyobjc-framework-AddressBook==2.5.1
pyobjc-framework-AppleScriptKit==2.5.1
pyobjc-framework-AppleScriptObjC==2.5.1
pyobjc-framework-Automator==2.5.1
pyobjc-framework-CFNetwork==2.5.1
pyobjc-framework-Cocoa==2.5.1
pyobjc-framework-Collaboration==2.5.1
pyobjc-framework-CoreData==2.5.1
pyobjc-framework-CoreLocation==2.5.1
pyobjc-framework-CoreText==2.5.1
pyobjc-framework-DictionaryServices==2.5.1
pyobjc-framework-EventKit==2.5.1
pyobjc-framework-ExceptionHandling==2.5.1
pyobjc-framework-FSEvents==2.5.1
pyobjc-framework-InputMethodKit==2.5.1
pyobjc-framework-InstallerPlugins==2.5.1
pyobjc-framework-InstantMessage==2.5.1
pyobjc-framework-LatentSemanticMapping==2.5.1
pyobjc-framework-LaunchServices==2.5.1
pyobjc-framework-Message==2.5.1
pyobjc-framework-OpenDirectory==2.5.1
pyobjc-framework-PreferencePanes==2.5.1
pyobjc-framework-PubSub==2.5.1
pyobjc-framework-QTKit==2.5.1
pyobjc-framework-Quartz==2.5.1
pyobjc-framework-ScreenSaver==2.5.1
pyobjc-framework-ScriptingBridge==2.5.1
pyobjc-framework-SearchKit==2.5.1
pyobjc-framework-ServiceManagement==2.5.1
pyobjc-framework-Social==2.5.1
pyobjc-framework-SyncServices==2.5.1
pyobjc-framework-SystemConfiguration==2.5.1
pyobjc-framework-WebKit==2.5.1
pyOpenSSL==0.14
pyparsing==2.0.1
PySide==1.2.2
python-dateutil==2.4.2
python-qt5==0.1.8
pytz==2013.7
pyzmq==14.5.0
QtPy==0.1.2
requests==2.6.0
rsa==3.1.4
scipy==0.13.0b1
six==1.9.0
snowballstemmer==1.2.0
Sphinx==1.3.1
sphinx-rtd-theme==0.1.7
terminado==0.5
tornado==4.1
Twisted==13.2.0
virtualenv==12.0.7
xattr==0.6.4
zope.interface==4.1.1
@vrivellino
I would try to read the file in as binary by using fileb:// instead of file://. file:// trys to read it in as text, which will result in decoding errors for a zip file because a zip file is not encoded in the first place. Here is a blog post that describes the topic a bit more: http://blogs.aws.amazon.com/cli/post/TxLWWN1O25V1HE/Best-Practices-for-Local-File-Parameters
Ugh - nice catch. fileb:// does indeed correct this.
@kyleknap Thanks for the tip! I guess it would be nice for the awscli to spit out a more informative error in this case.
Yep we thought the error message needed improvement as well. We recently merged a pull request to create a better error message: https://github.com/aws/aws-cli/pull/1296. This will be available in the next release of the CLI.
Closing issue.
Event before-building-argument-table-parser.lambda.create-function: calling handler <bound method OverrideRequiredArgsArgument.override_required_args of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument
In my case everything is working fine though but the lambda creation with environment variables is causing issue.
('runtime', <awscli.arguments.CLIArgument object at 0x7fa2d2d5de48>), ('role', <awscli.arguments.CLIArgument object at 0x7fa2d2d5deb8>), ('handler', <awscli.arguments.CLIArgument object at 0x7fa2d2d5df28>), ('code', <awscli.arguments.CLIArgument object at 0x7fa2d2d5df98>), ('description', <awscli.arguments.CLIArgument object at 0x7fa2d2d5dfd0>), ('timeout', <awscli.arguments.CLIArgument object at 0x7fa2d2d62080>), ('memory-size', <awscli.arguments.CLIArgument object at 0x7fa2d2d620b8>), ('publish', <awscli.arguments.BooleanArgument object at 0x7fa2d2d62128>), ('no-publish', <awscli.arguments.BooleanArgument object at 0x7fa2d2d62160>), ('vpc-config', <awscli.arguments.CLIArgument object at 0x7fa2d2d62198>)])
2017-12-13 13:48:07,238 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.lambda.create-function: calling handler <function add_streaming_output_arg at 0x7fa2d2ed2620>
2017-12-13 13:48:07,238 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.lambda.create-function: calling handler <function _extract_code_and_zip_file_arguments at 0x7fa2d3310840>
2017-12-13 13:48:07,243 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.lambda.create-function: calling handler <function add_cli_input_json at 0x7fa2d3310d90>
2017-12-13 13:48:07,243 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.lambda.create-function: calling handler <function unify_paging_params at 0x7fa2d2f1ea60>
2017-12-13 13:48:07,244 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/lib/python3/dist-packages/botocore/data/lambda/2015-03-31/paginators-1.json
2017-12-13 13:48:07,245 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.lambda.create-function: calling handler <function add_generate_skeleton at 0x7fa2d2f89a60>
2017-12-13 13:48:07,245 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.lambda.create-function: calling handler <bound method OverrideRequiredArgsArgument.override_required_args of <awscli.customizations.cliinputjson.CliInputJSONArgument object at 0x7fa2d2d5df98>>
2017-12-13 13:48:07,245 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.lambda.create-function: calling handler <bound method OverrideRequiredArgsArgument.override_required_args of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7fa2d2d62470>>
usage: aws [options]
aws help
aws
Unknown options: --environment Variables={key=val}
Any idea ??