[DOCKER] [I get] Until deploying with SAM CLI

AWS CLI installation

Addition of python and pip path * First stage work

・ How to check the path of python and pip Check with explorer

pythonのpath確認方法.PNG

・ Addition of path Open the following from the command prompt System and Security → System → Advanced System Settings → Environment Variables Select Path from the list of system environment variables and click Edit

pythonのpath追加.PNG

If there is no python and pip Path, create a new one

AWS CLI installation

C:\Users\USER>pip install awscli
Defaulting to user installation because normal site-packages is not writeable
Collecting awscli
  Downloading awscli-1.18.157-py2.py3-none-any.whl (3.4 MB)
     |████████████████████████████████| 3.4 MB 504 kB/s

Installing collected packages: six, python-dateutil, jmespath, urllib3, botocore, PyYAML, pyasn1, rsa, s3transfer, colorama, docutils, awscli
  WARNING: The scripts pyrsa-decrypt.exe, pyrsa-encrypt.exe, pyrsa-keygen.exe, pyrsa-priv2pub.exe, pyrsa-sign.exe and pyrsa-verify.exe are installed in 'C:\Users\USER\AppData\Roaming\Python\Python37\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed PyYAML-5.3.1 awscli-1.18.157 botocore-1.18.16 colorama-0.4.3 docutils-0.15.2 jmespath-0.10.0 pyasn1-0.4.8 python-dateutil-2.8.1 rsa-4.5 s3transfer-0.3.3 six-1.15.0 urllib3-1.25.10
WARNING: You are using pip version 20.1.1; however, version 20.2.3 is available.
You should consider upgrading via the 'c:\program files (x86)\microsoft visual studio\shared\python37_64\python.exe -m pip install --upgrade pip' command.

The first WARNING needs to be added because the Path does not pass. Path to add is described in WARNING

The second WARNING is a guide that you can update to the latest version with a simple pip upgrade

AWS CLI settings

C:\Users\USER>aws configure --profile IoT AWS Access Key ID [None]: ### AWS Secret Access Key [None]: ### Default region name [None]: ap-northeast-1 Default output format [None]: json

Confirmation after setting Confirmation of ec2

aws ec2 describe-instances --instance-ids ${instance-id} --profile IoT

Confirmation of S3

C:\Users\USER>aws s3 ls --profile IoT
2020-10-10 14:46:01 test7712121

AWS SAM CLI installation

Installation of Docker * First stage work

First of all, Task Manager → Performance tab → CPU Confirm that the "Virtual" field at the bottom right is enabled.

仮想の有効確認.png

Dokcer Desktop for Windows is not included in Windows 10 Home when installing Docker. This time I decided to install Docker Toolbox instead. Install v19.03.1 from "Install Docker Toolbox for Windows" from the following site https://docs.docker.com/toolbox/overview/

screencapture-docs-docker-toolbox-overview-2020-10-10-15_28_55.png

I installed it without changing the contents. docker導入.PNG

If the following installation is displayed during the installation of Docker, install it. docker_2.PNG

AWS SAM CLI installation

Download the installer from below https://github.com/awslabs/aws-sam-cli/releases/download/v0.6.2/AWS_SAM_CLI_64_PY3.msi

Version confirmation command

C:\Users\USER>sam --version
SAM CLI, version 0.6.2

Unlike the behavior that init thought, I could not specify it When I try to build, I get a situation where I can't! !!

Actually, it turned out that the installer version was old, so Install the latest SAM and it will be solved!

Build and deploy

First with sam init using AWS SAM template Initialize the serverless application. By the way, it's okay only at the first time such as when changing the project.

This time the setting is        : 1 - AWS Quick Start Templates Language: 8-python3.7 Project name  : test2 templates   : 1 - Hello World Example

C:\Users\USER\test>sam init
Which template source would you like to use?
        1 - AWS Quick Start Templates
        2 - Custom Template Location
Choice: 1

Which runtime would you like to use?
        1 - nodejs12.x
        2 - python3.8
        3 - ruby2.7
        4 - go1.x
        5 - java11
        6 - dotnetcore3.1
        7 - nodejs10.x
        8 - python3.7
        9 - python3.6
        10 - python2.7
        11 - ruby2.5
        12 - java8.al2
        13 - java8
        14 - dotnetcore2.1
Runtime: 8

Project name [sam-app]: test2

Cloning app templates from https://github.com/awslabs/aws-sam-cli-app-templates.git

AWS quick start application templates:
        1 - Hello World Example
        2 - EventBridge Hello World
        3 - EventBridge App from scratch (100+ Event Schemas)
        4 - Step Functions Sample App (Stock Trader)
Template selection:
Template selection: 1

-----------------------
Generating application:
-----------------------
Name: test2
Runtime: python3.7
Dependency Manager: pip
Application Template: hello-world
Output Directory: .

Next steps can be found in the README file at ./test2/README.md

This time I was able to specify as I expected Run it with the --guided option required for the first time, Here is the result of bilud and deploy start, but there is an error again ...

C:\Users\USER\sam_test>sam build
Building codeuri: hello_world/ runtime: python3.7 metadata: {} functions: ['HelloWorldFunction']
Running PythonPipBuilder:ResolveDependencies
Running PythonPipBuilder:CopySource

Build Succeeded

Built Artifacts  : .aws-sam\build
Built Template   : .aws-sam\build\template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided
sam deploy --guided --profile IoT

Configuring SAM deploy
======================

        Looking for config file [samconfig.toml] :  Not found

        Setting default arguments for 'sam deploy'
        =========================================
        Stack Name [sam-app]: sam_test
        AWS Region [us-east-1]: ap-northeast-1
        #Shows you resources changes to be deployed and require a 'Y' to initiate deploy
        Confirm changes before deploy [y/N]: N
        #SAM needs permission to be able to create roles to connect to the resources in your template
        Allow SAM CLI IAM role creation [Y/n]: Y
        HelloWorldFunction may not have authorization defined, Is this okay? [y/N]: y
        Save arguments to configuration file [Y/n]: Y
        SAM configuration file [samconfig.toml]:
        SAM configuration environment [default]:

        Looking for resources needed for deployment: Not found.
        Creating the required resources...
        Successfully created!


Initiating deployment
=====================
HelloWorldFunction may not have authorization defined.
Uploading to sam_test/25efe53b4bac655770621572b615acba.template  1132 / 1132.0  (100.00%)
Error: Failed to create changeset for the stack: sam_test, An error occurred (ValidationError) when calling the CreateChangeSet operation: 1 validation error detected: Value 'sam_test' at 'stackName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z][-a-zA-Z0-9]*|arn:[-a-zA-Z0-9:/._+]*

Actually, it was an error because "_" could not be used for stackName due to a simple mistake. I solved it by editing the contents of the samconfig.toml file. After fixing, I tried to build and deploy and it was successful.

Recommended Posts

[I get] Until deploying with SAM CLI
I tried to get started with WebAssembly
I tried to get started with Spring Data JPA
I want to get along with Map [Java beginner]
How to get jdk etc from oracle with cli
CLI creation with thor
I played with Refinements
Get started with Gradle
I tried to get started with Swagger using Spring Boot