如何使用无服务器 Azure 管道部署 Python 应用?



我尝试通过Azure DevOps管道部署无服务器python应用程序。

serverless.yml

service: ws-serverless
provider:
name: aws
runtime: python3.7
websocketApiName: ws-serverless-api
websocketApiRouteSelectionExpression: $request.body.action
stage: dev
region: ap-northeast-2
iamRoleStatements:
- Effect: "Allow"
Action:
- "execute-api:ManageConnections"
Resource: 
- "arn:aws:execute-api:*:*:**/@connections/*"
- Effect: "Allow"
Action:
- "dynamodb:PutItem"
- "dynamodb:GetItem"
- "dynamodb:UpdateItem"
- "dynamodb:DeleteItem"
- "dynamodb:BatchGetItem"
- "dynamodb:BatchWriteItem"
- "dynamodb:Scan"
- "dynamodb:Query"
Resource: 
- "arn:aws:dynamodb:ap-northeast-2:*:*"
functions:
connectionManager:
handler: handler.connection_manager
events:
- websocket:
route: $connect
- websocket:
route: $disconnect
defaultMessage:
handler: handler.default_message
events:
- websocket:
route: $default
getRecentMessages:
handler: handler.get_recent_messages
events:
- websocket:
route: getRecentMessages
sendMessage:
handler: handler.send_message
events:
- websocket:
route: sendMessage
ping:
handler: handler.ping
events:
- http:
path: ping
method: get
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
dockerizePip: true
noDeploy: []

azure-pipelines.yml

trigger:
- test
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.7'
addToPath: true
displayName: Install Python
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install --no-cache
displayName: 'npm install'
- task: AWSShellScript@1
inputs:
awsCredentials: aws
regionName: 'ap-northeast-2'
scriptType: 'inline'
inlineScript: |
./node_modules/.bin/serverless package --stage dev --region ap-northeast-2 --package /tmp/dev_artifacts/
displayName: Package for Dev Environment
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: /tmp/dev_artifacts
artifactName: dev_artifacts
displayName: Export Dev Artifacts

它在Package for Dev Environment上失败

了我收到此错误消息

错误:ENOENT:没有这样的文件或目录,打开'/home/vsts/work/1/s/venv/bin/python'

所以我尝试使用Virtualenv在该路径中安装Python,但它也失败了。

FileExistsError: [Errno 17] File exists: '/opt/hostedtoolcache/Python/3.7.7/x64/bin/python' -> '/home/vsts/work/1/s/venv/bin/python'

我以一种不同的方式做到了。我使用了全局安装serverless软件包。但一切都很顺利。(几乎所有,工作目录对我不起作用,所以我不得不直接导航到文件夹(。我希望它对您有所帮助:

trigger:
- test
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.7'
addToPath: true
displayName: Install Python
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
displayName: 'npm install dependency'
- script: |
npm install serverless -g
displayName: 'npm install serverless'
- task: AWSShellScript@1
inputs:
awsCredentials: aws
workingDirectory: $(Build.SourcesDirectory)/stackoverflow/31-serverless-aws
regionName: 'ap-northeast-2'
scriptType: 'inline'
inlineScript: |
cd $(Build.SourcesDirectory)/stackoverflow/31-serverless-aws
ls
serverless package --stage dev --region ap-northeast-2 --package $(Build.ArtifactStagingDirectory)
displayName: Package for Dev Environment
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)
artifactName: dev_artifacts
displayName: Export Dev Artifacts

相关内容

  • 没有找到相关文章

最新更新