Visual Studio Code 용 AWS Toolkit 시도
12655 단어 AWS
개시하다
AWS Toolkit for Visual Studio Code가 이미 발매되었기 때문에 한번 해 보겠습니다.
SAM local과 협력하면 VScode를 통해 로컬 테스트 및 AWS 환경에 대한 디버깅을 수행할 수 있습니다.
https://www.publickey1.jp/blog/19/aws_toolkit_for_visual_studio_codeaws_lmabda.html
https://docs.aws.amazon.com/ja_jp/toolkit-for-vscode/latest/userguide/welcome.html
전제 조건
MAC 작업 구상
awscli가 설치되어 있음
aws-sam-cli ※ pythn 설치 시 3.6.4 이상 필요
pyenv local 3.6.4
pip install aws-sam-cli
절차.
Visual Studio Code 용 AWS Toolkit 설치
AWS 신용 설정
AWS에 연결
응용 프로그램 생성
로컬 테스트
프로그램 설계
시험해 보다
Visual Studio Code 용 AWS Toolkit 설치
왼쪽 창으로 Extentions 클릭

AWS Toolkit for Visual Studio Code 를 검색하고 Install 을 클릭합니다.

왼쪽 창에 AWS 아이콘 만들기

AWS 신용 설정
Explorer를 CMD+Shift+P로 열고 AWS:Create Credentials Profile을 실행합니다.

~/.aws/credentials 파일을 열기 때문에 액세스 키를 입력하십시오. 비밀 액세스 키를 입력하십시오.
[vscode]
aws_access_key_id = XXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXX
AWS에 연결
왼쪽 창에서 AWS 아이콘을 클릭합니다.
Connect to AWS를 클릭하십시오.

생성된 프로파일 가져오기

기존 Cloudformation 및 Lambda 표시
응용 프로그램 생성
Createnw SAM Application 을 클릭하십시오.

runtime 지정

Local의 항목 디렉토리 지정하기

응용 프로그램 이름 기재

SAM 템플릿 파일 작성 등
$ tree My1stApp/
My1stApp/
├── README.md
├── event.json
├── hello-world
│ ├── app.js
│ ├── package.json
│ └── tests
│ └── unit
│ └── test-handler.js
└── template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
My1stApp
Sample SAM Template for My1stApp
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello-world/
Handler: app.lambdaHandler
Runtime: nodejs10.x
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /hello
Method: get
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: "Implicit IAM Role created for Hello World function"
Value: !GetAtt HelloWorldFunctionRole.Arn
로컬 테스트
제작된 앱입니다.js를 열면 "Run Locally", "Debug Locally", "Configure"가 표시되며 클릭하여 실행할 수 있습니다.

Run Locally 를 클릭합니다.
sam local을 실행하고 테스트용 Docker 이미지를 다운로드하여 테스트를 수행합니다.
Preparing to run app.lambdaHandler locally...
Building SAM Application...
Build complete.
Starting the SAM Application locally (see Terminal for output)
Running command: sam local invoke awsToolkitSamLocalResource --template /tmp/aws-toolkit-vscode/vsctk7VFCcJ/output/template.yaml --event /tmp/aws-toolkit-vscode/vsctk7VFCcJ/event.json --env-vars /tmp/aws-toolkit-vscode/vsctk7VFCcJ/env-vars.json
2019-07-17 12:25:29 Invoking app.lambdaHandler (nodejs10.x)
Fetching lambci/lambda:nodejs10.x Docker container image......
2019-07-17 12:25:33 Mounting /tmp/aws-toolkit-vscode/vsctk7VFCcJ/output/awsToolkitSamLocalResource as /var/task:ro,delegated inside runtime container
-略-
[32mREPORT RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Duration: 51.24 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 44 MB [0m
{"statusCode":200,"body":"{\"message\":\"hello world\"}"}
Local invoke of SAM Application has ended.
프로그램 설계
Explorer를 CMD+Shift+P로 열고 AWS:Deploy SAM Application을 실행합니다.

SAM의 템플릿 파일 선택

대상 영역 지정

S3 구간 지정

Stack 이름 입력

Starting SAM Application deployment...
Building SAM Application...
Packaging SAM Application to S3 Bucket: XXXX with profile: vscode
Deploying SAM Application to CloudFormation Stack: myapp with profile: vscode
Successfully deployed SAM Application to CloudFormation Stack: myapp with profile: vscode
디버그된 Lambda 함수를 마우스 오른쪽 버튼으로 클릭하고 Invoke on AWS를 클릭합니다.
local에 있는 vnet입니다.json 실행 지정

확인 성공.
Loading response...
Invocation result for arn:aws:lambda:ap-northeast-1:XXXXXX:function:myapp-HelloWorldFunction-EXCZ2RTGP7SE
Logs:
START RequestId: 1f4736fc-960b-4b98-9183-da8e978ebcf8 Version: $LATEST
END RequestId: 1f4736fc-960b-4b98-9183-da8e978ebcf8
REPORT RequestId: 1f4736fc-960b-4b98-9183-da8e978ebcf8 Duration: 106.54 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 62 MB
Payload:
{"statusCode":200,"body":"{\"message\":\"hello world\"}"}
Loading response...
Invocation result for arn:aws:lambda:ap-northeast-1:XXXXXX:function:myapp-HelloWorldFunction-EXCZ2RTGP7SE
Logs:
START RequestId: b4a3420d-2ba8-4bdc-b21b-6b0f20b35252 Version: $LATEST
END RequestId: b4a3420d-2ba8-4bdc-b21b-6b0f20b35252
REPORT RequestId: b4a3420d-2ba8-4bdc-b21b-6b0f20b35252 Duration: 27.32 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 62 MB
Payload:
{"statusCode":200,"body":"{\"message\":\"hello world\"}"}
투고 내용은 제 개인적인 의견으로 소속 기업과 부서의 견해를 대표하지 않습니다.
Reference
이 문제에 관하여(Visual Studio Code 용 AWS Toolkit 시도), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/atsumjp/items/481a6eacd58358ddcd8e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)