AWS CDK安装到AWS EC2 Linux 2

文章目录

小结

AWS CDK安装到AWS EC2 Linux 2,并记录过程。

问题及解决

安装NPM

shell 复制代码
[ec2-user@ip-100-92-28-119 aws]$ sudo yum install npm
Loaded plugins: priorities, update-motd, upgrade-helper
amzn2-core                                                                                                                                                                                         | 3.6 kB  00:00:00     
amzn2extra-ecs                                                                                                                                                                                     | 2.9 kB  00:00:00     
amzn2extra-epel                                                                                                                                                                                    | 3.0 kB  00:00:00     
amzn2extra-mate-desktop1.x                                                                                                                                                                         | 3.0 kB  00:00:00     
amzn2extra-python3.8                                                                                                                                                                               | 2.9 kB  00:00:00     
epel/x86_64/metalink                                                                                                                                                                               | 4.9 kB  00:00:00     
epel                                                                                                                                                                                               | 4.7 kB  00:00:00     
(1/2): epel/x86_64/updateinfo                                                                                                                                                                      | 1.0 MB  00:00:00     
(2/2): epel/x86_64/primary_db                                                                                                                                                                      | 7.0 MB  00:00:00     
311 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package npm.x86_64 1:8.19.4-1.16.20.2.1.el7 will be installed
--> Processing Dependency: nodejs = 1:16.20.2-1.el7 for package: 1:npm-8.19.4-1.16.20.2.1.el7.x86_64
--> Running transaction check
---> Package nodejs.x86_64 1:16.20.2-1.el7 will be installed
--> Processing Dependency: nodejs-libs(x86-64) = 1:16.20.2-1.el7 for package: 1:nodejs-16.20.2-1.el7.x86_64
--> Processing Dependency: libuv >= 1:1.43.0 for package: 1:nodejs-16.20.2-1.el7.x86_64
--> Processing Dependency: openssl11 >= 1:1.1.1 for package: 1:nodejs-16.20.2-1.el7.x86_64
--> Processing Dependency: libbrotlidec.so.1()(64bit) for package: 1:nodejs-16.20.2-1.el7.x86_64
--> Processing Dependency: libbrotlienc.so.1()(64bit) for package: 1:nodejs-16.20.2-1.el7.x86_64
--> Processing Dependency: libcrypto.so.1.1()(64bit) for package: 1:nodejs-16.20.2-1.el7.x86_64
--> Processing Dependency: libnode.so.93()(64bit) for package: 1:nodejs-16.20.2-1.el7.x86_64
--> Processing Dependency: libssl.so.1.1()(64bit) for package: 1:nodejs-16.20.2-1.el7.x86_64
--> Processing Dependency: libuv.so.1()(64bit) for package: 1:nodejs-16.20.2-1.el7.x86_64
--> Running transaction check
---> Package libbrotli.x86_64 0:1.0.9-10.el7 will be installed
---> Package libuv.x86_64 1:1.39.0-1.amzn2 will be installed
---> Package nodejs.x86_64 1:16.20.2-1.el7 will be installed
--> Processing Dependency: libuv >= 1:1.43.0 for package: 1:nodejs-16.20.2-1.el7.x86_64
---> Package nodejs-libs.x86_64 1:16.20.2-1.el7 will be installed
---> Package openssl11.x86_64 1:1.1.1g-12.amzn2.0.19 will be installed
---> Package openssl11-libs.x86_64 1:1.1.1g-12.amzn2.0.19 will be installed
--> Processing Dependency: openssl11-pkcs11 for package: 1:openssl11-libs-1.1.1g-12.amzn2.0.19.x86_64
--> Running transaction check
---> Package nodejs.x86_64 1:16.20.2-1.el7 will be installed
--> Processing Dependency: libuv >= 1:1.43.0 for package: 1:nodejs-16.20.2-1.el7.x86_64
---> Package openssl11-pkcs11.x86_64 0:0.4.10-6.amzn2.0.1 will be installed
--> Finished Dependency Resolution
Error: Package: 1:nodejs-16.20.2-1.el7.x86_64 (epel)
           Requires: libuv >= 1:1.43.0
           Available: 1:libuv-1.23.2-1.amzn2.0.2.i686 (amzn2-core)
               libuv = 1:1.23.2-1.amzn2.0.2
           Available: 1:libuv-1.39.0-1.amzn2.i686 (amzn2-core)
               libuv = 1:1.39.0-1.amzn2
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

以上报·epel·提供的·libuv·版本过低,关闭·epel·的·YUM·源,

shell 复制代码
[ec2-user@ip-100-92-28-119 deployment_automation_script]$ ls /etc/yum.repos.d/
amzn2-core.repo  amzn2-extras.repo  epel.repo.bak  epel-testing.repo.bak

安装aws-cdk-lib

shell 复制代码
[ec2-user@ip-100-92-28-119 aws]$ python3.8 -m pip install aws-cdk-lib

[ec2-user@ip-100-92-28-119 aws]$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15916  100 15916    0     0  48438      0 --:--:-- --:--:-- --:--:-- 48376
=> nvm is already installed in /home/ec2-user/.nvm, trying to update using git
=> => Compressing and cleaning up git repository

=> nvm source string already in /home/ec2-user/.bashrc
=> bash_completion source string already in /home/ec2-user/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
[ec2-user@ip-100-92-28-119 aws]$ . ~/.nvm/nvm.sh
[ec2-user@ip-100-92-28-119 aws]$ nvm install --lts
Installing latest LTS version.
Downloading and installing node v20.10.0...
Local cache found: ${NVM_DIR}/.cache/bin/node-v20.10.0-linux-x64/node-v20.10.0-linux-x64.tar.xz
Checksums match! Using existing downloaded archive ${NVM_DIR}/.cache/bin/node-v20.10.0-linux-x64/node-v20.10.0-linux-x64.tar.xz
Now using node v20.10.0
[ec2-user@ip-100-92-28-119 aws]$ npm install -g aws-cdk
node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)

以上报没找到GLIBC库,卸载版本20.10.0,安装版本16.0.0:

shell 复制代码
[ec2-user@ip-100-92-28-119 aws]$ nvm uninstall 20.10.0
Uninstalled node v20.10.0
[ec2-user@ip-100-92-28-119 aws]$ nvm install 16.0.0
v16.0.0 is already installed.
Now using node v16.0.0 (npm v10.2.4)
[ec2-user@ip-100-92-28-119 aws]$ npm install -g aws-cdk
npm WARN cli npm v10.2.4 does not support Node.js v16.0.0. This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.

changed 1 package in 2s
npm notice 
npm notice New patch version of npm available! 10.2.4 -> 10.2.5
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.2.5
npm notice Run npm install -g npm@10.2.5 to update!
npm notice 

找不到Python3

碰到了没有找到Python3的问题,

shell 复制代码
[ec2-user@ip-100-92-28-119 hello-ecs]$ cdk bootstrap
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!                                                                            !!
!!  Node 16 has reached end-of-life on 2023-09-11 and is not supported.       !!
!!  Please upgrade to a supported node version as soon as possible.           !!
!!                                                                            !!
!!  This software is currently running on node v16.0.0.                       !!
!!  As of the current release of this software, supported node releases are:  !!
!!  - ^20.0.0 (Planned end-of-life: 2026-04-30)                               !!
!!  - ^18.0.0 (Planned end-of-life: 2025-04-30)                               !!
!!                                                                            !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/bin/sh: python3: command not found

Subprocess exited with error 127

由于我使用的是Python3.8,需要创建一个软链接:

shell 复制代码
[ec2-user@ip-100-92-28-119 bin]$ ls python*
python  python2  python2.7  python2.7-config  python2-config  python3  python3.8  python3.8-config  python3.8-x86_64-config  python-config

[ec2-user@ip-100-92-28-119 hello-ecs]$ ll /usr/bin/python*
lrwxrwxrwx 1 root root    7 Nov  1 20:24 /usr/bin/python -> python2
lrwxrwxrwx 1 root root    9 Nov  1 20:24 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 7048 Oct 19 21:17 /usr/bin/python2.7
-rwxr-xr-x 1 root root 1846 Oct 19 21:17 /usr/bin/python2.7-config
lrwxrwxrwx 1 root root   16 Nov  1 20:24 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root    9 Dec 28 04:30 /usr/bin/python3 -> python3.8
-rwxr-xr-x 1 root root 7048 Aug 30 23:21 /usr/bin/python3.8
-rwxr-xr-x 1 root root  171 Aug 30 23:20 /usr/bin/python3.8-config
-rwxr-xr-x 1 root root 3397 Aug 30 23:13 /usr/bin/python3.8-x86_64-config
lrwxrwxrwx 1 root root   14 Nov  1 20:24 /usr/bin/python-config -> python2-config



[ec2-user@ip-100-92-28-119 bin]$ sudo ln -s python3.8 /usr/bin/python3

测试

shell 复制代码
[ec2-user@ip-100-92-28-119 aws]$ mkdir hello-ecs
[ec2-user@ip-100-92-28-119 aws]$ cd hello-ecs/
[ec2-user@ip-100-92-28-119 hello-ecs]$ cdk init --language python
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!                                                                            !!
!!  Node 16 has reached end-of-life on 2023-09-11 and is not supported.       !!
!!  Please upgrade to a supported node version as soon as possible.           !!
!!                                                                            !!
!!  This software is currently running on node v16.0.0.                       !!
!!  As of the current release of this software, supported node releases are:  !!
!!  - ^20.0.0 (Planned end-of-life: 2026-04-30)                               !!
!!  - ^18.0.0 (Planned end-of-life: 2025-04-30)                               !!
!!                                                                            !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Applying project template app for python

# Welcome to your CDK Python project!

This is a blank project for CDK development with Python.

The `cdk.json` file tells the CDK Toolkit how to execute your app.

This project is set up like a standard Python project.  The initialization
process also creates a virtualenv within this project, stored under the `.venv`
directory.  To create the virtualenv it assumes that there is a `python3`
(or `python` for Windows) executable in your path with access to the `venv`
package. If for any reason the automatic creation of the virtualenv fails,
you can create the virtualenv manually.

To manually create a virtualenv on MacOS and Linux:


$ python3 -m venv .venv


After the init process completes and the virtualenv is created, you can use the following
step to activate your virtualenv.


$ source .venv/bin/activate


If you are a Windows platform, you would activate the virtualenv like this:


% .venv\Scripts\activate.bat


Once the virtualenv is activated, you can install the required dependencies.


$ pip install -r requirements.txt


At this point you can now synthesize the CloudFormation template for this code.


$ cdk synth


To add additional dependencies, for example other CDK libraries, just add
them to your `setup.py` file and rerun the `pip install -r requirements.txt`
command.

## Useful commands

 * `cdk ls`          list all stacks in the app
 * `cdk synth`       emits the synthesized CloudFormation template
 * `cdk deploy`      deploy this stack to your default AWS account/region
 * `cdk diff`        compare deployed stack with current state
 * `cdk docs`        open CDK documentation

Enjoy!

Initializing a new git repository...
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'ec2-user@ip-100-92-28-119.(none)')
Unable to initialize git repository for your project.
Please run 'python3 -m venv .venv'!
Executing Creating virtualenv...
/bin/sh: python3: command not found
Unable to create virtualenv automatically
Please run 'python3 -m venv .venv'!
✅ All done!

参考

aws-cdk-lib 2.116.0
AWS: Getting started with the AWS CDK
stackoverflow: creating an alias for python3
stackoverflow: nodejs-16 dependency issue with libuv
Installing NPM on AWS EC2

相关推荐
watermelonoops10 分钟前
Deepin和Windows传文件(Xftp,WinSCP)
linux·ssh·deepin·winscp·xftp
疯狂飙车的蜗牛1 小时前
从零玩转CanMV-K230(4)-小核Linux驱动开发参考
linux·运维·驱动开发
远游客07133 小时前
centos stream 8下载安装遇到的坑
linux·服务器·centos
马甲是掉不了一点的<.<3 小时前
本地电脑使用命令行上传文件至远程服务器
linux·scp·cmd·远程文件上传
jingyu飞鸟3 小时前
centos-stream9系统安装docker
linux·docker·centos
超爱吃士力架4 小时前
邀请逻辑
java·linux·后端
cominglately6 小时前
centos单机部署seata
linux·运维·centos
魏 无羡6 小时前
linux CentOS系统上卸载docker
linux·kubernetes·centos
CircleMouse6 小时前
Centos7, 使用yum工具,出现 Could not resolve host: mirrorlist.centos.org
linux·运维·服务器·centos
木子Linux7 小时前
【Linux打怪升级记 | 问题01】安装Linux系统忘记设置时区怎么办?3个方法教你回到东八区
linux·运维·服务器·centos·云计算