Skip to content

Commit d34a1ea

Browse files
committed
ecr
1 parent acf6e0b commit d34a1ea

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

.github/workflows/newaws.yml

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env:
1010
PYTHON_VERSION: 3.11
1111
AWS_REGION: us-east-1
1212
ECR_REPOSITORY: meta/hello-world
13+
LAMBDA_FUNCTION_NAME: lamdanew2234
1314
permissions:
1415
id-token: write
1516
contents: read
@@ -54,7 +55,9 @@ jobs:
5455
# Step 3: Docker image build and push (optional)
5556
docker:
5657
runs-on: ubuntu-latest
57-
58+
outputs:
59+
image-uri: ${{ steps.build-image.outputs.image }}
60+
5861
steps:
5962
- name: Checkout code
6063
uses: actions/checkout@v4
@@ -80,28 +83,28 @@ jobs:
8083
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
8184
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
8285
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
83-
# deploy:
84-
# name: Deploy to EC2
85-
# runs-on: ubuntu-latest
86-
# needs: docker
87-
# steps:
88-
# - name: Setup SSH key
89-
# run: |
90-
# mkdir -p ~/.ssh
91-
# echo -e "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa
92-
# chmod 600 ~/.ssh/id_rsa
93-
94-
# - name: Add EC2 host to known hosts
95-
# run: |
96-
# ssh-keyscan -H ${{ vars.EC2_HOST }} >> ~/.ssh/known_hosts
97-
98-
# - name: Deploy Docker container on EC2
99-
# run: |
100-
# ssh -i ~/.ssh/id_rsa ${{ vars.EC2_USER }}@${{ vars.EC2_HOST }} << 'EOF'
101-
# docker pull manojkumar8008/myapp1:latest
102-
# docker stop myapp || true
103-
# docker rm myapp || true
104-
# docker run -d --name myapp -p 80:8000 manojkumar8008/myapp1:latest
105-
# EOF
86+
deploy:
87+
needs: docker
88+
runs-on: ubuntu-latest
89+
90+
steps:
91+
- name: Configure AWS credentials
92+
uses: aws-actions/configure-aws-credentials@v4
93+
with:
94+
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
95+
role-session-name: GitHubActions-Deploy
96+
aws-region: ${{ env.AWS_REGION }}
10697

98+
- name: Update Lambda function
99+
env:
100+
IMAGE_URI: ${{ needs.docker.outputs.image-uri }}
101+
run: |
102+
aws lambda update-function-code \
103+
--function-name ${{ env.LAMBDA_FUNCTION_NAME }} \
104+
--image-uri $IMAGE_URI
105+
106+
- name: Wait for Lambda function update to complete
107+
run: |
108+
aws lambda wait function-updated \
109+
--function-name ${{ env.LAMBDA_FUNCTION_NAME }}
107110

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def hello(event, context):
55
return {
66
'statusCode': 200,
77
'body': json.dumps({
8-
'message': 'Hello from Lambda!',
8+
'message': 'Hello Lambda!',
99
'version': '1.0'
1010
        })
1111
    }

0 commit comments

Comments
 (0)